How can I get a output data frame with most repeated value in each row for its corresponding row ?
df <- data.frame(x=seq(1:10), y=seq(1:10), z=sample(1:10), w=sample(1:10), v=sample(1:10))
I tried apply
but it didn't output the correct answer : apply(df, 1, frequency)
solved by following :
getmode <- function(v) {
uniqv <- unique(v)
uniqv[which.max(tabulate(match(v, uniqv)))]
}
Then
apply(df, 1, getmode)