#1.Sinh 600 số ngẫu nhiên từ phân phối nhị thức
set.seed(123)  
n <- 20
p <- 0.5
data <- rbinom(600, n , p )  

# 2.Vẽ biểu đồ histogram
hist(data, col="blue", main="Histogram", xlab="Giá trị", ylab="Tần suất", probability=TRUE)

#Vẽ đường cong phân phối chuẩn
mean_val <- n * p  
sd_val <- sqrt(n * p * (1 - p))  

x <- seq(min(data), max(data), length=100) 
y <- dnorm(x, mean=mean_val, sd=sd_val) 
lines(x, y, col="red", lwd=2) 

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

# 1. Đọc tập dữ liệu Iris
data(iris)

# 2. Tính giá trị trung bình của từng đặc trưng theo từng loại hoa
mean_values <- aggregate(. ~ Species, data=iris, FUN=mean)
print(mean_values)
##      Species Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1     setosa        5.006       3.428        1.462       0.246
## 2 versicolor        5.936       2.770        4.260       1.326
## 3  virginica        6.588       2.974        5.552       2.026
# 3. Tính độ lệch chuẩn của từng đặc trưng theo từng loại hoa
sd_values <- aggregate(. ~ Species, data=iris, FUN=sd)
print(sd_values)
##      Species Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1     setosa    0.3524897   0.3790644    0.1736640   0.1053856
## 2 versicolor    0.5161711   0.3137983    0.4699110   0.1977527
## 3  virginica    0.6358796   0.3224966    0.5518947   0.2746501
# 4. Vẽ biểu đồ Boxplot cho chiều rộng đài hoa (Sepal.Width)
boxplot(Sepal.Width ~ Species, data=iris, col="lightblue",
        main="Boxplot của Sepal Width theo loài",
        xlab="Loài hoa", ylab="Chiều rộng đài hoa (Sepal Width)")