该modeest
包提供了实现单峰单变量数据模式的许多估计器。
这有一个函数mfv
可以返回最频繁的值,或者(作为?mfv
状态)使用 `mlv(..., method = 'discrete') 可能更好
library(modeest)
## assuming your data is in the data.frame dd
apply(dd[,2:6], 1,mfv)
[1] 5 7 4 2
## or
apply(dd[,2:6], 1,mlv, method = 'discrete')
[[1]]
Mode (most frequent value): 5
Bickel's modal skewness: -0.2
Call: mlv.integer(x = newX[, i], method = "discrete")
[[2]]
Mode (most frequent value): 7
Bickel's modal skewness: -0.4
Call: mlv.integer(x = newX[, i], method = "discrete")
[[3]]
Mode (most frequent value): 4
Bickel's modal skewness: -0.4
Call: mlv.integer(x = newX[, i], method = "discrete")
[[4]]
Mode (most frequent value): 2
Bickel's modal skewness: 0.4
Call: mlv.integer(x = newX[, i], method = "discrete")
现在,如果你有最频繁的关系,那么你需要考虑你想要什么。
两者都mfv
将mlv.integer
返回所有最常见的值。(虽然 print 方法只显示一个值)