filmov
tv
Calculate Median in R (5 Examples) | Remove NA, Vector Object, Data Frame Column, by Group & Boxplot
![preview_player](https://i.ytimg.com/vi/m3UnwMs1dIU/maxresdefault.jpg)
Показать описание
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
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)
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:
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
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)
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: