What is the fastest way to compute the number of occurrences for each unique element in a vector in R?
So far, I\'ve tried the following five functions:
There's almost nothing that will beat tabulate()
provided you can meet the initial conditions.
x <- sample(1:100, size=1e7, TRUE)
system.time(tabulate(x))
# user system elapsed
# 0.071 0.000 0.072
@dickoa adds a few more notes in the comments as to how to get the appropriate output, but tabulate as a workhorse function is the way to go.