When I convert a vector to a matrix that has too few elements to fill the matrix, then the elements of the vector are recycled. Is there any way to turn recycling off or otherwise replace the recycled elements with NA?
This is the default behavior:
> matrix(c(1,2,3,4,5,6,7,8,9,10,11),ncol=2,byrow=TRUE)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
[4,] 7 8
[5,] 9 10
[6,] 11 1
Warning message:
In matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), ncol = 2, byrow = TRUE) :
data length [11] is not a sub-multiple or multiple of the number of rows [6]
I would like the resulting matrix to be
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
[4,] 7 8
[5,] 9 10
[6,] 11 NA
See Question&Answers more detail:
os