Skip to content

Instantly share code, notes, and snippets.

@ttimbers
Created October 22, 2016 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttimbers/39ecb9032ba78a5de3261899e389a32a to your computer and use it in GitHub Desktop.
Save ttimbers/39ecb9032ba78a5de3261899e389a32a to your computer and use it in GitHub Desktop.
test <- as.character(c(1,1,1,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,1,1,1))
test_rle <- rle(test)
unique_lengths <- make.unique(as.character(test_rle$lengths))
data.frame(unique_lengths,test_rle$lengths)
group_labels <- rep(unique_lengths, test_rle$lengths)
data.frame(test,group_labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment