I\'m very surprised this question has not been asked, maybe the answer will clear up why. I want to compare rows of a matrix to a vector and return whether the row == the v
The package prodlim
has a function called row.match
, which is easy to use and ideal for your problem. First install and load the library: library(prodlim)
. In our example, row.match
will return '5' because the 5th row in M
is equal to v
. We can then convert this into a logical vector.
m <- row.match(v, M)
m==1:NROW(M)#[1] FALSE FALSE FALSE FALSE TRUE