I am using R in a Windows environment.
I have a basic question regarding lm().
I have a dataframe data1 with ncol=w.
I know that my dependent variable is in column1.
Is there a way to write the regression formula so that
I can use columns 2 thru w as my independent
variables?
e.g.
Try:
lm(Sepal.Length ~., iris)
On 8/10/06, r user [EMAIL PROTECTED] wrote:
I am using R in a Windows environment.
I have a basic question regarding lm().
I have a dataframe data1 with ncol=w.
I know that my dependent variable is in column1.
Is there a way to write the regression formula
lm(data1) should work just fine. E.g.,
R data1 - data.frame(v1=rnorm(10), v2=rnorm(10), v3=rnorm(10))
R lm(data1)
Call:
lm(formula = data1)
Coefficients:
(Intercept) v2 v3
0.5746 0.3363 -0.5549
Andy
From: r user
I am using R in a Windows
You could look at using lm.fit instead of lm.
Alternatively, you can paste the names of the variables together using
the following approach. It's a bit baroque, but it works:
form.fn - function (dframe) {
nms - names(dframe)
formula(paste(nms[1], ~, paste(nms[2:length(nms)], collapse=+)))
}