Brief decsription of mode value

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

Create the function.

getmode <- function(y) {
   uniqv <- unique(y)
   uniqv[which.max(tabulate(match(y, uniqv)))]
}

Create the vector with numbers.

y <- c(4,1,2,3,1,2,3,4,1,5,5,3,2,3)

Calculate the mode using the user function.

Output <- getmode(y)
print(Output)
## [1] 3

Create the vector with characters.

charvalue <- c("o","it","the","it","it")

Calculate the mode using the user function.

Output1 <- getmode(charvalue)
print(Output1)
## [1] "it"

END