Skip to content
Prev 50129 / 398498 Next

Converting data frame to array?

Dear Thomas,

In fact, the more common way to fit a linear regression in R is to use
variables in a data frame (or list) along with a model formula specifying
the model. All of this is explained in the Introduction to R manual that is
distributed with R: see, in particular, Sec. 6.3 on data frames, Sec. 7 on
reading data from files, and Sec. 11 on statistical models.

Given two data frames, say d1 and d2, the first containing, e.g.,
observations on variables x1 and x2 and the second on y, one could do lm(y ~
x1 + x2, data=c(x1, x2)) or lm(y ~ x1 + x2, data=data.frame(x1, x2)). 

That said, it's not altogether clear to me what it is that you're trying to
do. Are there 10 observations on 300 variables in the first data frame,
constituting the predictors, and 10 observations on 1 variable in the second
data frame, constituting the response? If so, you have many more predictors
than observations, and it's not reasonable to perform a regression. Of
course, I may not have this straight.

I hope this helps,
 John