Skip to content
Prev 306505 / 398506 Next

How to test if there is a subvector in a longer vector

Hi!
28.09.2012 08:41, Atte Tenkanen wrote:
How about this:

--- code ---

g1<- c(2,1,1,4,6,3)
g2<- c(2,1,1,6,4,3)
t1<- c(1,4,6)
t2<-c(9,8)

!is.na(sum(match(t1,g1)))
[1] TRUE
!is.na(sum(match(t1,g2)))
[1] TRUE
!is.na(sum(match(t2,g1)))
[1] FALSE

--- code ---

Kind regads,
Kimmo