[R] as.matrix behaves weird
Alexx Hardt
mikrowelle1234 at gmx.de
Sun Nov 14 19:02:03 CET 2010
Hi,
can someone tell me why x is still a 2x1-matrix in the last step?
> x <- 1:2
> x
[1] 1 2
> t(x)
[,1] [,2]
[1,] 1 2
> x <- as.matrix(x,ncol=2)
> x
[,1]
[1,] 1
[2,] 2
I figured out that if I use "x <- matrix(x,ncol=2)", instead of
as.matrix(), it works fine. What exactly is the difference between
matrix() and as.matrix() here?
The help file describes the two functions with different words, but the
essence sounds like the same to me.
Thanks in advance,
Alex
More information about the R-help
mailing list