[R] looping through variables

K. Fleischer K.Fleischer at student.uva.nl
Wed Sep 24 17:15:58 CEST 2008

Hello everyone,

I have the following problem:

My analysis includes many predictor variables (>50) in the form of 
raster maps (asc), but I am trying to avoid having to type all their 
names over and over again in the analysis (e.g. for vectorisation, for 
deletion of NA's, etc.)

So ideally I would like to store them in some way that their names 
only have to be typed once and can always be referred back to.

First step would be to automate the vectorisation of the raster maps:

# these are the raster maps which need to combined somehow ??
variables <- (temperature, precipitation, elevation, vegcover) 


For (i in 1:length(variables)) {
Varnew <- as.vector(variables[i])
VariablesNew <- cbind(VariablesNew, Varnew)

This should return a data frame called VariablesNew with each column 
representing one of the variables. 

So the BIG QUESTION is how to input the variable names that they can 
be referred to easily and, the variable itself can be pulled out and 
not just its name!!
I believe this cant be too difficult??

Thanx in advance,

More information about the R-help mailing list