a) Tính giá trị lớn nhất, nhỏ nhất và độ lệch chuẩn của Sepal.Width
theo Species
data(iris)
write.csv(iris, "iris.csv", row.names = FALSE)
aggregate(
Sepal.Width ~ Species,
data = iris,
FUN = function(x) c(
Min = min(x),
Max = max(x),
SD = sd(x)
)
)
## Species Sepal.Width.Min Sepal.Width.Max Sepal.Width.SD
## 1 setosa 2.3000000 4.4000000 0.3790644
## 2 versicolor 2.0000000 3.4000000 0.3137983
## 3 virginica 2.2000000 3.8000000 0.3224966
b) Vẽ boxplot Sepal.Length theo từng nhóm Species bằng ggplot2
library(ggplot2)
ggplot(iris, aes(x = Species, y = Sepal.Length)) +
geom_boxplot() +
labs(title = "Boxplot Sepal.Length theo Species",
x = "Species",
y = "Sepal.Length"
)
