Find the most frequent value by row

Something like : apply(df,1,function(x) names(which.max(table(x)))) [1] “red” “yellow” “green” In case there is a tie, which.max takes the first max value. From the which.max help page : Determines the location, i.e., index of the (first) minimum or maximum of a numeric vector. Ex : var4 <- c(“yellow”,”green”,”yellow”) df <- data.frame(cbind(id, var1, var2, var3, var4)) > … Read more