Use mapply instead

On Fri, Nov 16, 2012 at 5:01 PM, billycorg <candi...@gmail.com> wrote:
> Hi R Users.
>
> I have a simple question on a loop.
>
> The following loop works fine:
>
> r_t=list()
> for(i in 1:500)
> {
> r_t[[i]]=h_t_half[[i]]%*%matrix(*z_t_m*[i,])
> }
>
> But indeed I need also that *z_t_m* varies. Let us suppose that *z_t_m* has
> 1000 replicates,
> I have written the following loop that (naturally) does not work.
>
> r_t <- list()
> for(r in 1:replicate)
> {
> for(i in 1:499)
> {
> r_t[[r]][[i]]=h_t_half[[i]]%*%matrix(*z_t_m*[[r]][i,])
> }
> }
>
> If, for instance, I try to do
>
> h_t_half[[1]]%*%matrix(*z_t_m*[[1000]][1,])
>
> I effectively obtain (only one row of) r_t.  But I need to have 1000
> replications of the whole r_t, that has 500 rows.
>
> Do you have any suggestions?
>
> Thank you!!!
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/simple-question-on-loop-tp4649761.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Mehmet Süzen, Ph.D. ( Dr.phil.nat. )
<su...@acm.org>

| PRIVILEGED AND CONFIDENTIAL COMMUNICATION This e-mail transmission,
and any documents, files or previous e-mail messages attached to it,
may contain confidential information that is legally privileged. If
you are not the intended recipient or a person responsible for
delivering it to the intended recipient, you are hereby notified that
any disclosure, copying, distribution or use of any of the information
contained in or attached to this transmission is STRICTLY PROHIBITED
within the applicable law. If you have received this transmission in
error, please: (1) immediately notify me by reply e-mail to
su...@acm.org,  and (2) destroy the original transmission and its
attachments without reading or saving in any manner. |

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to