Skip to content
Prev 178755 / 398503 Next

Select the same rows

It is unclear what you really want so here are two solutions to two  
different questions:

 > A <- matrix(c(0,1,2,0,1,0,1,2,3,4), ncol=1)
 > A
       [,1]
  [1,]    0
  [2,]    1
  [3,]    2
  [4,]    0
  [5,]    1
  [6,]    0
  [7,]    1
  [8,]    2
  [9,]    3
[10,]    4

 > A[A[,1] %in% c(2,1,4) , ]
[1] 1 2 1 1 2 4
# the value of the entries in the rows where that attains.
# not interesting in itself other than allowing a count,
# but possibly useful if you were interested in a matrix with more  
columns

 > which(A[,1] %in% c(2,1,4) )
[1]  2  3  5  7  8 10
#the row numbers where membership in that set occurs.
On Apr 28, 2009, at 10:35 PM, sangduan jansomboon wrote:

            
David Winsemius, MD
Heritage Laboratories
West Hartford, CT