目标是根据列及其数据检索模式。
data <- data.frame(test=c("a","b","c","a","a","a","a","c","c","c","c","c","c"))
是否有R内置函数或标准方法来计算data$test
的模式?
答案 0 :(得分:2)
table(data$test)
#a b c
#5 1 7
table(data$test)==max(table(data$test))
# a b c
#FALSE FALSE TRUE
或
names(table(data$tes)[table(data$test)==max(table(data$test))])
#[1] "c"