[R] keep only the first value of a numeric sequence
Jorge I Velez
jorgeivanvelez at gmail.com
Mon Dec 15 13:18:33 CET 2014
Here is one way:
ifelse(with(data, c(0, diff(mydata))) != 1, 0, 1)
You could also take a look at ?rle
On Mon, Dec 15, 2014 at 9:33 PM, jeff6868 <geoffrey_klein at etu.u-bourgogne.fr
> Hello dear R-helpers,
> I have a small problem in my algorithm. I have sequences of "0" and "1"
> values in a column of a huge data frame, and I just would like to keep the
> first value of each sequences of "1" values, such like in this example:
> data <-
> Any easy way to do this?
> Thanks everybody!
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help