Re: [R] How to test if there is a subvector in a longer vector

2012-09-28 Thread Atte Tenkanen
Thank you! ___ Lähettäjä: Berend Hasselman [b...@xs4all.nl] Lähetetty: 28. syyskuuta 2012 10:47 Vastaanottaja: Atte Tenkanen Cc: R help Aihe: Re: [R] How to test if there is a subvector in a longer vector On 28-09-2012, at 07:41, Atte Tenkanen wrote: > Sorry. I should have mentio

Re: [R] How to test if there is a subvector in a longer vector

2012-09-28 Thread Berend Hasselman
On 28-09-2012, at 07:41, Atte Tenkanen wrote: > Sorry. I should have mentioned that the order of the components is important. > > So c(1,4,6) is accepted as a subvector of c(2,1,1,4,6,3), but not of > c(2,1,1,6,4,3). > > How to test this? See this discussion for a variety of solutions. http

Re: [R] How to test if there is a subvector in a longer vector

2012-09-27 Thread K. Elo
Hi! 28.09.2012 08:41, Atte Tenkanen wrote: Sorry. I should have mentioned that the order of the components is important. So c(1,4,6) is accepted as a subvector of c(2,1,1,4,6,3), but not of c(2,1,1,6,4,3). How to test this? How about this: --- code --- g1<- c(2,1,1,4,6,3) g2<- c(2,1,1,6,4

Re: [R] How to test if there is a subvector in a longer vector

2012-09-27 Thread Atte Tenkanen
Sorry. I should have mentioned that the order of the components is important. So c(1,4,6) is accepted as a subvector of c(2,1,1,4,6,3), but not of c(2,1,1,6,4,3). How to test this? Cc: R help Aihe: Re: [R] How to test if there is a subvector in a longer

Re: [R] How to test if there is a subvector in a longer vector

2012-09-27 Thread arun
Hi, Try this: Not sure whether this is the fastest: set.seed(932) vec1<-sample(1:10,6,replace=TRUE)  vec2<-sample(1:7,3,replace=TRUE)  vec2[vec2%in%vec1] #[1] 5 library(rbenchmark)  benchmark(isTRUE(all(vec2%in%vec1)),replications=1e4) # test replications elapsed relative us

Re: [R] How to test if there is a subvector in a longer vector

2012-09-27 Thread David Winsemius
On Sep 27, 2012, at 2:00 PM, Atte Tenkanen wrote: > Hi, > > There are certainly several ways to test, whether a longer vector includes a > subvector. > For instance, c(1,4,6) is included in c(2,1,1,4,6,3). How to test this and > which would be the fastest way to do it? > > all( c(1,4,6) %in