[R] Sorting dataframe by number of occurrences of factor

Oliver oliver at first.in-berlin.de
Sat Apr 30 22:58:36 CEST 2011


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), ]



More information about the R-help mailing list