I am creating a simple 3x3 matrix with 9 values using the as.matrix() function. But the output I am seeing seems to be incorrect. What am I missing?
Here's what I am doing:
> s <- as.matrix(c(3,4,5,6,7,8,9,10,11),nrow = 3,ncol = 3)
What I expect to see:
> s
[,1] [,2] [,3]
[1,] 3 6 9
[2,] 4 7 10
[3,] 5 8 11
But What I actually see:
> s
[,1]
[1,] 3
[2,] 4
[3,] 5
[4,] 6
[5,] 7
[6,] 8
[7,] 9
[8,] 10
[9,] 11
>
What am I missing?
The documentation for as.matrix() function says that nrow and ncol are used to defined the desired number of rows and columns. Any pointers?
as.matrixvs. simplymatrix, you will see that their API is different.matrixtakes the arguments you have in your example (i.e.nrowandncol) howeveras.matrixhas the ellipsis...as its second argument which are "additional arguments to be passed to or from methods". - Joseph Wood