Suppose I have a vector in R:
x <- c("a", "a", "b", "a", "b", "c")
I need to determine, for each position i
of the vector, how many times the x[i]
element has appeared so far. The result for the above vector would be
[1] 1 2 1 3 2 1
How to do this calculation efficiently and without using native code (C)? By efficient I mean something that runs in a second or less in a vector of 1 million elements (ex. x <- sample.int(1:99, size=999999, replace=T)
)