[R] Getting names of variables without quotes
Dieter Menne
dieter.menne at menne-biomed.de
Sun Oct 19 17:59:06 CEST 2008
Amarjit Singh Sethi <set_alt <at> yahoo.co.in> writes:
(Please do not use tabs when sending a data sample, these must be
manually edited)
V1,V2,V3
15,10,4
6,4,7
10,5,2
8,6,6
This does the work. However, I fear that you are going to use it on
100 variables, and I would strongly advice againts searching for
linear relations
that way.
Dieter
x=read.table("sample.txt",header=T,sep=",")
nm = names(x)
for (i in 1:2)
{
for(j in (i+1):3) # note that you need the ()!
{
formula= as.formula(paste(nm[i],"~",nm[j],sep=""))
slr=lm(formula, data=x)
smr=summary(slr)
print(smr)
}
}
More information about the R-help
mailing list