Majority vote in R

前端 未结 4 1845
名媛妹妹
名媛妹妹 2021-01-13 02:40

I need to calculate the majority vote for an item in R and I don\'t have a clue how to approach this.

I have a data frame with items and assigned categories. What I

4条回答
  •  逝去的感伤
    2021-01-13 03:19

    If you have a function to calculate the mode, as in package prettyR, you can use aggregate:

    require(prettyR)
    
    aggregate(d$category, by=list(item=d$item), FUN=Mode)
    #  item x
    #1    1 2
    #2    2 1
    

提交回复
热议问题