Hi Ashta,
Take a look at ?rle, e.g.

> rle(x1)
Run Length Encoding
  lengths: int [1:4] 2 3 1 1
  values : num [1:4] 1 0 1 0
> rle(x1)$lengths
[1] 2 3 1 1
> rle(x1)$values
[1] 1 0 1 0

HTH,
Jorge


On Tue, Oct 20, 2009 at 10:10 AM, Ashta <> wrote:

> Hi All,
>
> Assume that I have the following data set  with two variables and I
> want count the number of observation with identical values  and number
> of time each factor changed from x1 to x2.
>
> x1  x2
>  1    1
>  1    0
>  0    1
>  0    1
>  0    0
>  1    1
>  0    1
>
> The output should be
> x1  changed
>                      0   3    # has changed 3 times
>                      1   1    # has changed 1 time
> x1 unchanged
>                      0  1    # has unchanged only 1 time
>                      1  2     # has unchanged 2 times
>
> Can someone help me how to do it in R?
>
> Thanks in advance
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]


