The mode is the value that has highest number of occurrences in a set of data. Unike mean and median, mode can have both numeric and character data.
R does not have a standard in-built function to calculate mode. So we create a user function to calculate mode of a data set in R. This function takes the vector as input and gives the mode value as output.
Example
getmode <- function(y) {
uniqv <- unique(y)
uniqv[which.max(tabulate(match(y, uniqv)))]
}
y <- c(4,1,2,3,1,2,3,4,1,5,5,3,2,3)
Output <- getmode(y)
print(Output)
## [1] 3
charvalue <- c("o","it","the","it","it")
Output1 <- getmode(charvalue)
print(Output1)
## [1] "it"