Find the n most common values in a vector [duplicate]

I’m sure this is a duplicate, but the answer is simple:

sort(table(variable),decreasing=TRUE)[1:3]

Leave a Comment