Re: [R] a for loop to lapply

From: Nick Sabbe <nick.sabbe_at_ugent.be>
Date: Wed, 30 Mar 2011 09:35:17 +0200

Hello Alex.
A few issues:
* you want seq(dimx) instead of seq(1:dimx) (d'oh)

All in all, it seems you may need to get your basics up to speed first, then shift to *apply (and use a simpler example to get started, like: given a matrix with two columns, create a vector holding the differences and the sums of the columns - I know this can be done without *apply as well, but apart from that it is a more attainable exercise).

Good luck to you on that!

HTH, Nick Sabbe

--
ping: nick.sabbe_at_ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove




-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On
Behalf Of Alaios
Sent: woensdag 30 maart 2011 8:31
To: R-help_at_r-project.org
Subject: [R] a for loop to lapply

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}
lapply(seq(1:dimx),Shadowlist[,,seq(1:dimx)],returni)

So far I do not get same results with both ways.
Could you please help me understand what might be wrong?


Regards
Alex

______________________________________________
R-help_at_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.

______________________________________________
R-help_at_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.
Received on Wed 30 Mar 2011 - 07:44:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Mar 2011 - 08:20:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive