[R] matrix from list
lefevrol at yahoo.com
Sat Apr 26 17:53:05 CEST 2008
Martin Maechler wrote:
> The difference to as.matrix() is that data.matrix() also
> produces a numeric matrix in the case the data frame contains
Thanks, that is useful but it is becoming a little rococo: so may ways to
do this. Also, what if I have a list, not a data frame? read.table returns
a data frame but a select from a spreadsheet (via RODBC) returns a list.
> - I don't understand why you want to throw away the dimnames of
> the resulting numeric matrix. Rather, in general you'd want
> to keep them.
Merely because I find it confusing. When printing, which you do a lot of
when developing in interactive languages like R, list and as.matrix(list)
look absolutely the same, which is irksome and confusing since you have to
resort to mode to check what you've got, under penalty of strange errors
farther down. So I stick to the convention of unattributed matrices and
arrays in my code: that way it's easy to know which is which.
More information about the R-help