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
//biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios Sent: woensdag 30 maart 2011 8:31 To: R-help@r-project.org Subject: [R] a f

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

[R] a for loop to lapply

2011-03-29 Thread Alaios
Dear all, 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) {ShadowMatrix<-i} la