Majority vote in R

前端 未结 4 1889
名媛妹妹
名媛妹妹 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 03:21

    One liner (using plyr):

    ddply(dt, .(item), function(x) which.max(tabulate(x$category)))
    

提交回复
热议问题