Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
从矩阵中获取行作为矩阵的最短方法是什么?
> 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
我想去哪里
[,1] [,2] [,3] [1,] 1 2 3
[接受一个drop参数来控制提取的子集是否将被强制(如果可能)到一个低维对象(在这种情况下是一个普通向量)。为确保矩阵的子集始终是矩阵,请设置它drop=FALSE,如下所示:
[
drop
drop=FALSE
x[1,,drop=FALSE] [,1] [,2] [,3] [1,] 1 2 3
(对于全套子集规则和参数,请尝试help("[")。)
help("[")
t(as.matrix(x[1,]))
应该做的伎俩...