Skip to content

Instantly share code, notes, and snippets.

@phil8192
Created May 1, 2019 14:38
Show Gist options
  • Save phil8192/b9a514dfcc5f76bb48f46f9a39339044 to your computer and use it in GitHub Desktop.
Save phil8192/b9a514dfcc5f76bb48f46f9a39339044 to your computer and use it in GitHub Desktop.
# convert
# 7, 7, 6, 5, 5, 3, 3, 2, 0, 0 ->
# 1 1 2 3 3 4 4 5 NA NA
x <- c(7,7,6,5,5,3,3,2,0,0)
ifelse(x,cumsum(c(1,abs(sign(diff(x))))),NA)
# [1] 1 1 2 3 3 4 4 5 NA NA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment