select some values of a row in a matrix

后端 未结 2 1021
太阳男子
太阳男子 2021-01-21 15:11

In R with a matrix:

m <- matrix(1:20, ncol = 4) 
colnames(m) <- letters[1:4]

In the case I want to select just one value, it works. Like

相关标签:
2条回答
  • 2021-01-21 15:31

    Change == by %in%

    subset(m, m[,4] %in% c(17,19,20))
    
    0 讨论(0)
  • 2021-01-21 15:33

    without using subset

    m[ m[,4] %in% c(17, 19, 20),]
    
    0 讨论(0)
提交回复
热议问题