问题
When I try to subset a 1-colum matrix by it's row names the subsetting works but an numeric vector is returned.
can you somehow prevent that behaviour and keep the row names?
M<-as.matrix(rnorm(5))
rownames(M)<-LETTERS[1:5]
M
[,1]
A 0.6250957
B 0.7330598
C -0.7127075
D 0.2162602
E 0.2223444
M <- M[which(rownames(M) != "A")]
M
## [1] 0.7330598 -0.7127075 0.2162602 0.2223444
回答1:
you can read about argument drop
in the help page: ?'['
M[which(rownames(M) != "A"), ,drop=FALSE]
来源:https://stackoverflow.com/questions/28294590/subsetting-1-column-matrix-deletes-rownames