[R] count value changes in a column

jim holtman jholtman at gmail.com
Wed Jun 1 03:20:20 CEST 2011


Why isn't the sequence:

1 3 3 3 3 3 2 4 2 1 5 3 3 3

according to your rule about 5s following 3s.

On Tue, May 31, 2011 at 6:23 PM, Justin Haynes <jtor14 at gmail.com> wrote:
> is there a way to look for value changes in a column?
>
> set.seed(144)
> df<-data.frame(state=sample(rep(1:5,200),1000))
>
> any of the five states are acceptable.  however if, for example,
> states 4 or 5 follow state 3, i want to overwrite them with 3.
> changes from 1 to any value and 2 to any value are acceptable as are
> changes from any value to 1 or 2.
>
> By way of an example:
>
> the sequence 1 3 3 5 5 3 2 4 2 1 5 3 3 5
>
> should read   1 3 3 3 3 3 2 4 2 1 5 5 5 5
>
>
> Thanks for the help!
>
> Justin
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list