[R] Why can we combine design matrix and data-frame in R?
S Ellison
S.Ellison at LGCGroup.com
Mon May 14 02:10:51 CEST 2012
> But the line you cited was about "response" being a matrix, which is not our case.
Yes, you're right; I picked the wrong thing to cite.
The only documentation I found about lm accepting a matrix in the predictors is a one-line statement in "Introduction to R" which says "term_i
is either
a vector or matrix expression, or 1,
a factor, or
a formula expression consisting of factors, vectors or matrices connected by formula operators. "
Not the most informative documentation. But Peter Dalgaard is a most authoritative source!
>And also I have checked:
>
>Any more thoughts?
Data frames are odd things; a column need not contain only a vector if the number of rows is OK. I am half surprised that including a matrix in one works. But the gods of R are powerful and their magic is strong. Here, names(tmp) is showing that the data frame has one element called X (in effect, the whole matrix is regarded as one element of the data frame), but on display the magic has expanded X to show all the columns of X.
This is the main reason I generally keep to simple things in data frames; complicated things make it less easy to predict behaviour.
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
More information about the R-help
mailing list