I would like a function that works equivalent to cumsum but rather than adding up it counts the number of unique values so far. I could write a loop for each potential set but that seems like it could get time consuming as my dataset has millions of observations.
Example:
a <- c(1,3,2,4,1,5,2,3)
f(a)
[1] 1 2 3 4 4 5 5 5