How to get the top n elements (in terms of frequency) from a vector in R?
r
Solution
tab <- table(a<-c(67, 2, 100, 2, 100, 23, 2, 100, 67, 89,100))
df <- as.data.frame(tab)
names(df) <- c("number","times")
df$rank <- rank(-df$times,ties.method="min")
df <- df[order(df$rank,decreasing = F),]
df
number times rank
5 100 4 1
1 2 3 2
3 67 2 3
2 23 1 4
4 89 1 4
Problem
How can I get the top n ranking of an array in R? lets say I have `a <- c(67, 2, 100, 2, 100, 23, 2, 100, 67, 89,100)` how can I get: ``` rank number times 1 100 4 2 2 3 3 67 2 4 23 1 4 89 1 ```