The goal is to retrieve a mode based on the column and its data.
data <- data.frame(test=c("a","b","c","a","a","a","a","c","c","c","c","c","c"))
Is there an R built-in function or standard way to calculate the mode of data$test
?
The goal is to retrieve a mode based on the column and its data.
data <- data.frame(test=c("a","b","c","a","a","a","a","c","c","c","c","c","c"))
Is there an R built-in function or standard way to calculate the mode of data$test
?
table(data$test)
#a b c
#5 1 7
table(data$test)==max(table(data$test))
# a b c
#FALSE FALSE TRUE
or
names(table(data$tes)[table(data$test)==max(table(data$test))])
#[1] "c"