[R] Looping and actual variable names

Gordon, Alan Alan.Gordon at afbini.gov.uk
Tue Jan 24 16:15:31 CET 2012


Dear R users,

I'm a new user to R and have a data set consisting of a number of variables (in a data frame). I wish to carry out a regression analysis of the first variable against all the rest in turn. I have used the following code to do this

dd<-read.table("for loop.txt",header=T)
for (j in 2:5) print(summary(lm(formula = dd[,1] ~ dd[,j])))

However, although it produces all the analyses that I want, the output is annotated with dd[,1] and dd[,j] rather than the actual variable names. Is there any way around this?

Best wishes,
Alan.



More information about the R-help mailing list