wata...@post.com wrote:
-----Original Message-----
From: jas4710 <wata...@post.com>
To: r-help@r-project.org
Sent: Mon, Nov 22, 2010 4:11 pm
Subject: [R] how to loop through variables in R?
After importing a table with "M" variables and "N" records, I'd like to
calculate chi-square statistics, say, between N1, N2; N1, N3, ..., N1, Ni,
and then N2, N3, ... N2, Ni, ..., Ni-1, Ni. Two loops should be ok but the
manual & online help don't show a systematic way to do so but instead show
hard-code examples so users have to type in the names themselves one by
one...
Sorry for typo. It should be "N" variables and "M" records.
Thank you very much.
Assuming you are working with a data frame df, and your variable with
the name of a column in it is col1, you should be able to extract that
column as a vector using df[[col1]]. And yes, "the manual" does describe
this notation.
______________________________________________
R-help@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.