# Load the necessary library
library(gapminder)

## Mean
# Calculates the average life expectancy
mean_val <- mean(gapminder$lifeExp)
print(mean_val)

## Median
# Finds the middle value of life expectancy
median_val <- median(gapminder$lifeExp)
print(median_val)

## Mode
# Define a custom function to calculate the mode
getmode <- function(v) {
  uniqv <- unique(v)
  uniqv[which.max(tabulate(match(v, uniqv)))]
}

# Apply the function to the continent column
mode_val <- getmode(gapminder$continent)
print(mode_val)