Skip to content
Prev 258528 / 398502 Next

Sorting dataframe by number of occurrences of factor

to the first two lines of your solutions

df<-data.frame(id=c(1:20),name=c('a','b','b','c','a','d','b','e',
'd','d','c','a','b','a','a','b','f','b','c','g'))
freq <- ave(rep(1, times=nrow(df)), df$name, FUN=sum) 

I would add:

df[ sort.list(freq), ]