Skip to content

Instantly share code, notes, and snippets.

@czeildi
Created June 11, 2017 10:28
Show Gist options
  • Save czeildi/59d475a8ab2764faa2d4302dc06f433a to your computer and use it in GitHub Desktop.
Save czeildi/59d475a8ab2764faa2d4302dc06f433a to your computer and use it in GitHub Desktop.
compute cumulative unique N with R's data.table package
dt <- data.table(x = c(4,4,2,5,4,2,3))
dt[, g := .GRP, by = x]
dt[, cumuniquen := cummax(g)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment