Calculating most frequent level by category with plyr
问题 I would like calculate the most frequent factor level by category with plyr using the code below. The data frame b shows the requested result. Why does c$mlevels only have the value "numeric"? require(plyr) set.seed(0) a <- data.frame(cat=round(runif(100, 1, 3)), levels=factor(round(runif(100, 1, 10)))) mode <- function(x) names(table(x))[which.max(table(x))] b <- data.frame(cat=1:3, mlevels=c(mode(a$levels[a$cat==1]), mode(a$levels[a$cat==2]), mode(a$levels[a$cat==3]))) c <- ddply(a, .(cat),