[R] Find each time a value changes

Bill.Venables at csiro.au Bill.Venables at csiro.au
Thu Feb 11 03:16:11 CET 2010

something like this?

> c(1, which(c(0, diff(y)) != 0))
[1]  1 11 21 51 61 71 81 91

Bill Venables
CSIRO/CMIS Cleveland Laboratories

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Tim Clark
Sent: Thursday, 11 February 2010 11:59 AM
To: r-help at r-project.org
Subject: [R] Find each time a value changes

Dear List,

I am trying to find each time a value changes in a dataset.  The numbers are variables for day vs. night values, so what I am really getting is the daily sunrise and sunset.  

A simplified example is the following:

I would like to know each time the numbers change.
Correct answer should be:

I would appreciate any help or suggestions.  It seems like it should be simple but I'm stuck!



Tim Clark
Department of Zoology 
University of Hawaii

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list