Message-ID: <1348802003.78253.YahooMailNeo@web142604.mail.bf1.yahoo.com>
Date: 2012-09-28T03:13:23Z
From: arun
Subject: How to test if there is a subvector in a longer vector
In-Reply-To: <7953BA1D7779E746994B38A00362416C0B31E700@exch-mbx-02.utu.fi>
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 user.self sys.self
#1 isTRUE(all(vec2 %in% vec1))??????? 10000?? 0.295??????? 1???? 0.272??????? 0
#? user.child sys.child
#1????????? 0???????? 0
A.K.
----- Original Message -----
From: Atte Tenkanen <attenka at utu.fi>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Thursday, September 27, 2012 5:00 PM
Subject: [R] How to test if there is a subvector in a longer vector
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?
Best,
Atte Tenkanen, FT, MuM
http://users.utu.fi/attenka/
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.