[R] Saving iterative components

Liviu Andronic landronimirc at gmail.com
Tue Dec 14 11:48:38 CET 2010

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)


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.

Do you know how to read?
Do you know how to write?

More information about the R-help mailing list