Data frame linear fit in R

Posted by user1247384 on Stack Overflow See other posts from Stack Overflow or by user1247384
Published on 2012-10-03T21:34:55Z Indexed on 2012/10/03 21:37 UTC
Read the original article Hit count: 223

Filed under:
|
|

This is perhaps a simple question, but I am n00b.Say I have a data frame with a bunch of columns. I need to call lm function over the column 1 and 2, 1 and 3, and so on. So basically I need to loop over all columns and store the results of the fit as I build the model. The problem I am running into is that

lm(df[1]~df[2], data = df) doesnt work. In this case df is the data frame object and df[1] is the first column.

What is a good way to do this in a loop, as in access the columns of df in an iterative fashion.

Thanks.

© Stack Overflow or respective owner

Related posts about r

    Related posts about data