Hi,
Does anybody knows a easy way (without for-loops, maybe with something like match)
to solve this problem:
x <- rep(1,3)
y <- c(0,1,0,1,0,1,1,1,0,0,0,0,1,0)
if (x is a part of y){
find out where it is and
do something
}
Thanks a lot
Thomas
A little problem
2 messages · "Unternährer Thomas, uth", Brian Ripley
On Tue, 5 Aug 2003, "Untern?hrer Thomas, uth" wrote:
Hi,
Does anybody knows a easy way (without for-loops, maybe with something like match)
to solve this problem:
x <- rep(1,3)
y <- c(0,1,0,1,0,1,1,1,0,0,0,0,1,0)
if (x is a part of y){
find out where it is and
do something
}
I'll assume the contents are 0/1.
x0 <- paste(x, collapse="") y0 <- paste(y, collapse="") regexpr(x0, y0)
[1] 6 attr(,"match.length") [1] 3
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595