当前位置: 动力学知识库 > 问答 > 编程问答 >

Calculate mode in R

问题描述:

This question already has an answer here:

  • Is there a built-in function for finding the mode?

    25 answers

网友答案:

Here's another approach:

smode <-function(x){
    xtab<-table(x)
    modes<-xtab[max(xtab)==xtab]
    mag<-as.numeric(modes[1]) #in case mult. modes, this is safer
    themodes<-names(modes)
    mout<-list(themodes=themodes,modeval=mag)
    return(mout)
    }
分享给朋友:
您可能感兴趣的文章:
随机阅读: