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
tdat <- tapply(dat$category, dat$item, function(vec) sort(table(vec), decreasing=TRUE)[1] ) data.frame(item=rownames(tdat), plurality_vote=tdat) item plurality_vote 1 1 3 2 2 2
A more complex function would be needed to distinguish a plurality (possibly with ties) from a true majority.