Re: [R] matrix from list

From: Olivier Lefevre <lefevrol_at_yahoo.com>
Date: Sat, 26 Apr 2008 17:53:05 +0200

Martin Maechler wrote:
> The difference to as.matrix() is that data.matrix() also
> produces a numeric matrix in the case the data frame contains
> factors.

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.

Regards,


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 26 Apr 2008 - 16:33:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 Apr 2008 - 18:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive