Hallo, I have an other problem, I have this vector signData with an alternation of 1 and -1 that corrispond to the duration of two different percepts. I extracted the durations like this: signData<- scan("dataTR10.txt") dur<-rle(signData)$length Now I would like to extract only the positive duration, e.g. signData <- c(1,1,1,1,-1,-1,-1,1,1,-1,-1) posduration <- c(4,2) I think I should use rle in a nested way, this is what I tried but it doesn't work: posduration<- rle(signData[=1])$length Could you please help me? Thanks a lot, this forum is extremely useful. Ale -- View this message in context: http://www.nabble.com/rle-tp24371336p24371336.html Sent from the R help mailing list archive at Nabble.com.
Try this: rle(signData)$lengths[rle(signData)$values == 1] On Tue, Jul 7, 2009 at 8:11 AM, aledanda <danda.galli@gmail.com> wrote:> > Hallo, > > I have an other problem, I have this vector signData with an alternation of > 1 and -1 that corrispond to the duration of two different percepts. I > extracted the durations like this: > > signData<- scan("dataTR10.txt") > dur<-rle(signData)$length > > Now I would like to extract only the positive duration, e.g. > > signData <- c(1,1,1,1,-1,-1,-1,1,1,-1,-1) > posduration <- c(4,2) > > I think I should use rle in a nested way, this is what I tried but it > doesn't work: > > posduration<- rle(signData[=1])$length > > Could you please help me? > > Thanks a lot, this forum is extremely useful. > > Ale > -- > View this message in context: > http://www.nabble.com/rle-tp24371336p24371336.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
> I have an other problem, I have this vector signData with an alternationof> 1 and -1 that corrispond to the duration of two different percepts. I > extracted the durations like this: > > signData<- scan("dataTR10.txt") > dur<-rle(signData)$lengthI think that last line should be dur<-rle(signData)$lengths> Now I would like to extract only the positive duration, e.g. > > signData <- c(1,1,1,1,-1,-1,-1,1,1,-1,-1) > posduration <- c(4,2)If you know that the first element of signData will always be 1, then you can simply extract the first, third, fifth etc values from signdata, like so: posduration <- dur[c(TRUE, FALSE)] Otherwise you need to test to see if you are extracting odd or even elements. if(signData[1]==1) { index <- c(TRUE, FALSE) } else { index <- c(FALSE, TRUE) } posduration <- dur[index] Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}