如何检索值模式

时间:2014-10-12 12:22:21

标签: r

目标是根据列及其数据检索模式。

data <- data.frame(test=c("a","b","c","a","a","a","a","c","c","c","c","c","c"))

是否有R内置函数或标准方法来计算data$test的模式?

1 个答案:

答案 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"