How can the "["
function be used to select a column or a row of a matrix?
如何使用“[”函数来选择矩阵的列或行?
x <- matrix(1:4, ncol=2)
As far as I understand, these two lines do the same thing:
据我了解,这两行做同样的事情:
x[1,2]
"["(x,1,2)
Also these two:
还有这两个:
x[4]
"["(x,4)
But how can one rewrite
但如何重写呢
x[2,]
using "["(...) ?
使用“[”(...)?
1 个解决方案
#1
5
Just leave the argument blank
只需将参数留空即可
"["(x, 2, ) # second row
[1] 2 4
"["(x, ,2) # second column
[1] 3 4
#1
5
Just leave the argument blank
只需将参数留空即可
"["(x, 2, ) # second row
[1] 2 4
"["(x, ,2) # second column
[1] 3 4