Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

12. Write an R Program to Find Mean, Mode & Median. || R

 # Create the dataset 

data <- c(3, 3, 3, 4, 4, 4, 5, 5, 5) 

# Calculate the mean 

mean_value <- mean(data) 

# Calculate the median 

median_value <- median(data) 

# Calculate the mode 

find_mode <- function(x) { 

uniq_x <- unique(x) 

freq_x <- table(x) 

max_freq <- max(freq_x) 

mode <- as.numeric(names(freq_x[freq_x == max_freq])) 

return(mode) 

mode_value <- find_mode(data) 

# Print the results 

cat("Mean:", mean_value, "\n") 

cat("Median:", median_value, "\n") 

cat("Mode:", mode_value, "\n") 

Post a Comment

0 Comments