There is no built-in function in R to directly find the mode. However, you can create a custom function to calculate the mode.
Here's an example:
getMode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
# Example usage
data <- c(1, 2, 2, 3, 4, 4, 4, 5)
mode_value <- getMode(data)
print(mode_value)
Output:
[1] 4