[R] Annoyance in as.numeric

From: Alberto Monteiro <albmont_at_centroin.com.br>
Date: Mon, 16 Jun 2008 18:22:07 -0200


Why does as.numeric convert matrices and arrays to vectors?

as.numeric(matrix(c("1", "2", "3", "4"), 2, 2)) [1] 1 2 3 4

I could only figure out ugly ways to bypass this, like:

x <- matrix(c("1", "2", "3", "4"), 2, 2) array(as.numeric(x), dim = dim(x), dimnames = dimnames(x))

Alberto Monteiro



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 Mon 16 Jun 2008 - 20:48:23 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 Mon 16 Jun 2008 - 23:31:29 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