Skip to content
Prev 36239 / 63421 Next

y ~ X -1 , X a matrix

Ross Boylan wrote:
I'm pretty sure that it is per original design that data frames can have
matrix columns, although data.frame() and as.data.frame() are quite
trigger-happy when it comes to converting them to individual columns.
You need things like d <- data.frame(X=I(X)) to prevent it.

As you have seen, matrices can be handy on the RHS of formulas, but
there are at least two cases where they are crucial on the LHS,
multivariate linear models and one version of glm(Y~..., binomial).

Without being able to store matrices as individual components in a data
frame, I don't think you can avoid internally expanding model formula
into (say) Y ~ X1 + X2 - 1, which could get rather unwieldy, so I don't
think the feature will be going away. (Someone with too much time on
his/her hand might want to rationalize the whole data frame concept, but
that should go in the direction of handling all  matrix-like structures
consistently, including date-time objects etc.)