Calculate Median in R (5 Examples) | Remove NA, Vector Object, Data Frame Column, by Group & Boxplot
How to compute the median in the R programming language. More details: https://statisticsglobe.com/median-in-r-programming-function R code of this video: x1 <- c(8, 5, 3, 7, 8, 1, 6, 5) # Create example vector median(x1) # Apply median function x2 <- c(8, 5, 3, 7, 8, 1, 6, 5, NA) # Example vector with NA median(x2) # Apply median function median(x2, na.rm = TRUE) # median function with na.rm data(iris) # Load iris data head(iris) # Head of iris data median(iris$Sepal.Length) # Median of first column aggregate(iris$Sepal.Length, # Median by group list(iris$Species), median) set.seed(1717) # Set seed x3 <- rpois(1000, 3) # Create larger example vector boxplot(x3) # Boxplot with median text(x = 1, y = 3.25, # Add text to boxplot "Median of x3", col = "red") hist(x3) # Histogram in R abline(v = median(x3), # Add median to histogram col = "red", lwd = 3) text(x = 5, y = 200, # Add text to histogram "Median of x3", col = "red") Follow me on Social Media: Facebook – Statistics Globe Page: https://www.facebook.com/statisticsglobecom/ Facebook – Group for Discussions & Questions: https://www.facebook.com/groups/statisticsglobe LinkedIn – Statistics Globe Page: https://www.linkedin.com/company/statisticsglobe/ LinkedIn – Group for Discussions & Questions: https://www.linkedin.com/groups/12555223/ Twitter: https://twitter.com/JoachimSchork Music by bensound.com
Download
0 formatsNo download links available.