Re: [R] a for loop to lapply

2011-03-30 Thread Dieter Menne
alaios wrote: > > I am trying to learn lapply. > I would like, as a test case, to try the lapply alternative for the > Shadowlist<-array(data=NA,dim=c(dimx,dimy,dimmaps)) > for (i in c(1:dimx)){ > Shadowlist[,,i]<-i > } > ---so I wrote the following--- > returni <-function(i,ShadowMatrix) {S

Re: [R] a for loop to lapply

2011-03-30 Thread Kenn Konstabel
Hi Alex, lapply is not a substitute for for, so it not only does things differenly, it does a different thing. > Shadowlist<-array(data=NA,dim=c(dimx,dimy,dimmaps)) > for (i in c(1:dimx)){ >    Shadowlist[,,i]<-i > } Note that your test case is not reproducible as you haven't defined dimx, dimy

Re: [R] a for loop to lapply

2011-03-30 Thread Nick Sabbe
Hello Alex. A few issues: * you want seq(dimx) instead of seq(1:dimx) (d'oh) * I think you have problems with your dimensions in the original code as well: you use i, which runs up to dimx as an indexer for your third dimension, of size dimmaps. If dimx > dimmaps, you're in for unexpected results.

Re: [R] a for loop to lapply

2011-03-30 Thread Andreas Borg
Hi Alaios, there are some problems with your code: 1. In the expression "Shadowlist[,,i]<-i", i corresponds to dimmaps, not dimx. The for loop should be either for (i in c(1:dimmaps)){ Shadowlist[,,i]<-i } or for (i in c(1:dimx)){ Shadowlist[i,,]<-i } 2. in lapply, the function must