Check if vector in a matrix
问题 I have a matrix new<-matrix(9,4,4) new[1,1]<-0 v1<-c(0,0) new thus looks like this: 0 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 I now want to check if this matrix contains the vector v1. So I did v1 %in% new and obtain TRUE TRUE although I would like to check the whole vector of two zeros in a row/ column and thus would like to get a FALSE. 回答1: You can use rollapply from zoo to test if matrix contains a vector : library(zoo) any(apply(new, 2, rollapply, length(v1), identical, v1)) #[1] FALSE new[2,1] <-