Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Berend Hasselman
On 08-10-2012, at 18:00, Mike Spam wrote: > Great, works perfekt now! > Thanks for your fast help! See this discussion for a variety of solutions: http://r.789695.n4.nabble.com/matching-a-sequence-in-a-vector-td4389523.html#a4393453 (or here https://stat.ethz.ch/pipermail/r-help/2012-February/3

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Mike Spam
ounces@r- >> project.org] On Behalf Of Jessica Streicher >> Sent: Monday, October 08, 2012 9:19 AM >> To: Mike Spam >> Cc: r-help@r-project.org >> Subject: Re: [R] Simple - Finding vector in a vector >> >> > x<-c(NA , 1 ,NA, 1 , 1 , 1 , 1 , 1 ,1 ,N

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread David L Carlson
xas A&M University College Station, TX 77843-4352 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Jessica Streicher > Sent: Monday, October 08, 2012 9:19 AM > To: Mike Spam > Cc: r-help@r-project.org > S

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Jessica Streicher
> x<-c(NA , 1 ,NA, 1 , 1 , 1 , 1 , 1 ,1 ,NA , 1) > embed(x,3) [,1] [,2] [,3] [1,] NA1 NA [2,]1 NA1 [3,]11 NA [4,]111 [5,]111 [6,]111 [7,]111 [8,] NA11 [9,]1 NA1 > which(rowSums(embed(x,

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Steve Lianoglou
Ugh, typo: On Mon, Oct 8, 2012 at 10:04 AM, Steve Lianoglou 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

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Steve Lianoglou
Hi Mike, On Mon, Oct 8, 2012 at 9:38 AM, Mike Spam wrote: > Sorry, i just realized, that it output the sum of all vectors. I can > work with this function but it would be much faster and easier if it > would be possible to get the positions of evry match. > > example: > > NA 1 NA 1 1 1 1 1

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Mike Spam
Sorry, i just realized, that it output the sum of all vectors. I can work with this function but it would be much faster and easier if it would be possible to get the positions of evry match. example: NA 1 NA 1 1 1 1 1 1 NA 1 rle returns lengths: int [1:6] 1 1 1 6 1 1 what i need would

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Mike Spam
Hey Rui, Perfect! Thanks!! :) Nico 2012/10/8 Rui Barradas : > Hello, > > See ?rle > > Hope this helps, > > Rui Barradas > Em 08-10-2012 13:55, Mike Spam escreveu: >> >> Hi, >> >> just a simple question. >> Assumed i have a vector, >> >> FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE >> or

Re: [R] Simple - Finding vector in a vector

2012-10-08 Thread Rui Barradas
Hello, See ?rle Hope this helps, Rui Barradas Em 08-10-2012 13:55, Mike Spam escreveu: Hi, just a simple question. Assumed i have a vector, FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE or NA 1 1 1 NA 1 NA 1 NA what i need is the position where an element is the same - three (o

[R] Simple - Finding vector in a vector

2012-10-08 Thread Mike Spam
Hi, just a simple question. Assumed i have a vector, FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE FALSE or NA 1 1 1 NA 1 NA 1 NA what i need is the position where an element is the same - three (or in general multiple) times in a row. in this case: i want to get the position where it is