#median1

data_a <- c(10, 11, 15, 16, 19, 20, 89)
sorted_data <- sort(data_a)
n <- length(sorted_data)
if (n %% 2 == 1) {
  median_a <- sorted_data[(n + 1) / 2]
} else {
  median_a <- (sorted_data[n / 2] + sorted_data[n / 2 + 1]) / 2
}
print(median_a)
## [1] 16
#median2
data_b <- c(16 , 27 , 5 , 52 , 109 , 113 , 98 , 99)
sorted_data <- sort(data_b)
n <- length(sorted_data)
if (n %% 2 == 1) {
  median_b <- sorted_data[(n + 1) / 2]
} else {
  median_b <- (sorted_data[n / 2] + sorted_data[n / 2 + 1]) / 2
}
print(median_b)
## [1] 75

#mode1

calculate_mode <- function(data) {
  freq_table <- table(data)
  max_freq <- max(freq_table)
  mode <- as.numeric(names(freq_table[freq_table == max_freq]))
  return(mode)
}
data_set <- c(1, 2, 2, 4, 5, 3, 7, 3)
mode_result <- calculate_mode(data_set)
mode_result
## [1] 2 3

#mode2

mode_function <- function(x) {
  freq_table <- table(x)
  modes <- as.numeric(names(freq_table[freq_table == max(freq_table)]))
  return(modes)
}
data <- c(1, 2, 3)
mode_result <- mode_function(data)
print(mode_result)
## [1] 1 2 3

#mode3

# Define a function to calculate the mode
find_mode <- function(x) {
  # Calculate the frequency of each element
  freq_table <- table(x)
  # Find the element with the maximum frequency
  mode_values <- as.numeric(names(freq_table[freq_table == max(freq_table)]))
  return(mode_values)
}

# Data set
data <- c(10, 8, 8, 8, 9)

# Compute the mode
mode_result <- find_mode(data)
print(mode_result)
## [1] 8

#probability

P_A_and_B <- 0.133
P_B <- 0.262
P_A_given_B <- P_A_and_B / P_B
print(paste("The probability that an individual is male given they prefer math is:", round(P_A_given_B,4)))
## [1] "The probability that an individual is male given they prefer math is: 0.5076"