-----Original Message-----

From: Yuliya Matveyeva <yuliya.rmail@gmail.com>
To: watashi@post.com
Sent: Mon, Nov 22, 2010 4:32 pm
Subject: Re: [R] how to loop through variables in R?


If you want to have a name-specific loop.
Assign names to your variables after inserting them into the data.frame like that:
colnames(df) <- c("var1","var23","var456","var44",...)
for (nam in colnames(df)) {
 myfunction(df[[nam]])
}
Data.frames support access by names.


Unfortunately, in this sense I have to type in 1000 times... isn't there any function that allows retrieving and assigning all columns automatically? read.table in "the R intro manual" just brief says it can read a table but then there's no follow up about how to access the data....

 

	[[alternative HTML version deleted]]

