[R] A little problem
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Aug 5 11:06:18 CEST 2003
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
More information about the R-help
mailing list