[R] Simple - Finding vector in a vector

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon Oct 8 16:08:43 CEST 2012


Ugh, typo:

On Mon, Oct 8, 2012 at 10:04 AM, Steve Lianoglou
<mailinglist.honeypot at gmail.com> wrote:

> R> x <- c(NA,  1, NA,  1,  1,  1,  1,  1,  1, NA,  1)
> R> e <- embed(x, e) ## Take a look at this matrix
> R> r <- apply(e, 1, rle)
> R> sapply(r, function(rr) rr$lengths[1])
> ## [1] 1 1 2 3 3 3 3 1 1

The 2nd param to embed should be 3, so:

R> x <- c(NA,  1, NA,  1,  1,  1,  1,  1,  1, NA,  1)
R> e <- embed(x, 3) ## Take a look at this matrix
R> r <- apply(e, 1, rle)
R> sapply(r, function(rr) rr$lengths[1])
## [1] 1 1 2 3 3 3 3 1 1

Sorry for the confusion ... e and 3 are so close ;-)

-st3v3

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list