Skip to content

Instantly share code, notes, and snippets.

@RyanHope
Created October 5, 2012 13:41
Show Gist options
  • Save RyanHope/3839862 to your computer and use it in GitHub Desktop.
Save RyanHope/3839862 to your computer and use it in GitHub Desktop.
Find the indices of a vector where the data changes.
changes <- function(x) {
r <- rle(x)$lengths
c(0,cumsum(r[1:length(r)-1]))+1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment