简体   繁体   中英

How to use the “[” function to select a row / column of a matrix

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM