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 "["(...) ?
Just leave the argument blank
"["(x, 2, ) # second row
[1] 2 4
"["(x, ,2) # second column
[1] 3 4
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.