what shortest way obtain row matrix matrix?
> x<-matrix(1:9,nrow=3,byrow=true) > x [,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9 > x[1,] [1] 1 2 3 > is.vector(x[1,]) [1] true where i'd get
[,1] [,2] [,3] [1,] 1 2 3
[ takes drop argument controlling whether extracted subset coerced (if possible) lower dimensional object (in case plain vector). ensure subset of matrix matrix, set drop=false, this:
x[1,,drop=false] [,1] [,2] [,3] [1,] 1 2 3 (and full set of subsetting rules , arguments, try help("[").)
Comments
Post a Comment