如何将矩阵子集化为一列,维护矩阵数据类型,维护行/列名称?
当我将矩阵子集到单列时,结果是数字类,而不是矩阵(即 myMatrix[ , 5 ] 子集到第五列)。是否有一种紧凑的方法来子集为单列,维护矩阵格式,并维护行/列名称,而不需要做一些复杂的事情,例如:
matrix( myMatrix[ , 5 ] , dimnames = list( rownames( myMatrix ) , colnames( myMatrix )[ 5 ] )
When I subset a matrix to a single column, the result is of class numeric, not matrix (i.e. myMatrix[ , 5 ] to subset to the fifth column). Is there a compact way to subset to a single column, maintain the matrix format, and maintain the row/column names without doing something complicated like:
matrix( myMatrix[ , 5 ] , dimnames = list( rownames( myMatrix ) , colnames( myMatrix )[ 5 ] )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
使用
[
的drop=FALSE
参数。Use the
drop=FALSE
argument to[
.