[R] Detect numerical series
David Winsemius
dwinsemius at comcast.net
Sat Feb 11 16:08:17 CET 2012
On Feb 11, 2012, at 10:01 AM, syrvn wrote:
> Hello,
>
> I am struggling with detecting successive digits in a numerical series
> vector.
>
> Here is an example:
>
> vec <- c(1, 15, 26, 29, 30, 31, 37, 40, 41)
>
> I want to be able to detect 29, 30, 31 and 40, 41.
>
> Then, I would like to delete the successive digits from the vector.
>
> 1, 15, 26, 29, 37, 40
vec[ c(TRUE, !diff(vec) == 1) ]
#[1] 1 15 26 29 37 40
>
>
> Cheers
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Detect-numerical-series-tp4379088p4379088.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list