Saving iterative components
Hi, I'm trying to understand when and how to use do.call(). In this case, would it work with do.call() instead of lapply(), like this? vars <- list(names(Tmese[, -(1:2)])) res <- do.call(idw.cv, vars) Thanks, Ivan Le 12/14/2010 11:48, Liviu Andronic a ?crit :
On Tue, Dec 14, 2010 at 10:34 AM, Annalaura<annalaura.russo at imaa.cnr.it> wrote:
Thanks a lot Uwe Ligges, I've abandoned R for a few time but now I'm working
with it, so I've a question about the last problem that you solved: instead
to write
cv_1994<- idw.cv("X01_1994")
cv_1995<- idw.cv("X01_1995")
cv_1996<- idw.cv("X01_1996")
cv_1997<- idw.cv("X01_1997")
.....
cv_2006<- idw.cv("X01_2006")
cv_2007<- idw.cv("X01_2007")
cv_2008<- idw.cv("X01_2008")
can I use a more compact expression????
Yes. There are nicer ways to formulate the problem (and the solution), but without access to the object all I can is a shot in the dark. ##obtain a vector of variable names vars<- names(Tmese[, -(1:2)]) ##apply the function 'idw.cv' iteratively, each time ##using a 'vars' element as the functions first argument; ##store the results in a list res<- lapply(vars, idw.cv) res Regards Liviu PS For more on loops and the apply family check [1]. [1] http://promberger.info/files/rnews-vectorvsloops2008.pdf
Thanks -- View this message in context: http://r.789695.n4.nabble.com/Saving-iterative-components-tp2553676p3086697.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. S?ugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calandra at uni-hamburg.de ********** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php