Skip to content
Prev 258505 / 398502 Next

Sorting dataframe by number of occurrences of factor

On Fri, Apr 29, 2011 at 11:17:58PM -0700, adigs wrote:
Hi.

Try the following

  freq <- ave(rep(1, times=nrow(df)), df$name, FUN=sum)
  df[order(freq, df$name), ]

Hope this helps.

Petr Savicky.