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