rperformancecounttabulate

Is there an efficient alternative to table()?


I use the following command:

table(factor("list",levels=1:"n")

with "list": (example) a = c(1,3,4,4,3) and levels = 1:5, to also take the 2 and 5 into consideration. For really big datasets, my code seems to be very ineffective.

Does anyone know a hidden library or a code snippet to make it faster?


Solution

  • We could use fnobs from collapse which would be efficient

    library(collapse)
    fnobs(df, g = df$X1)
    

    In base R, tabulate is more efficient compared to table

     tabulate(df$X1)
     [1]  9  6 15 13 11  9  7  9 11 10