check whether matrix rows equal a vector in R , vectorized

前端 未结 3 520
刺人心
刺人心 2021-01-17 22:06

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

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 22:59

    Using DeMorgan's rule (Not all = Some not), then All equal = Not Some Not equal, we also have

    !colSums(t(M) != v)
    

提交回复
热议问题