[R] Annoyance in as.numeric

markleeds at verizon.net markleeds at verizon.net
Mon Jun 16 22:35:35 CEST 2008


  hi: you can do below but i don't know if it's worth it ?

newx <- data.matrix(data.frame(x))
print(newx)


On Mon, Jun 16, 2008 at  4:22 PM, Alberto Monteiro wrote:

> 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.



More information about the R-help mailing list