I have a data set for example,
Data <- data.frame(
groupname = as.factor(sample(c(\"a\", \"b\", \"c\"), 10, replace = TRUE)),
someuser = sample(c(\"x\
Many options. Here one using table to compute frequency and which.max to select max occurred. within data.table framework:
library(data.table)
setDT(Data)[,list(someuser={
tt <- table(someuser)
names(tt)[which.max(tt)]
}),groupname]
using plyr( nearly the same) :
library(plyr)
ddply(Data,.(groupname),summarize,someuser={
tt <- table(someuser)
names(tt)[which.max(tt)]
})