1. Load bộ dữ liệu

my_data <- faithful

2. Xem nhanh 6 dòng đầu của bộ dữ liệu

head(my_data)
##   eruptions waiting
## 1     3.600      79
## 2     1.800      54
## 3     3.333      74
## 4     2.283      62
## 5     4.533      85
## 6     2.883      55

3. Kiểm tra cấu trúc dữ liệu

str(my_data)
## 'data.frame':    272 obs. of  2 variables:
##  $ eruptions: num  3.6 1.8 3.33 2.28 4.53 ...
##  $ waiting  : num  79 54 74 62 85 55 88 85 51 85 ...

4. Tách biến thời gian phun

duration <- my_data$eruptions
rinh_chit <- my_data$waiting

head(duration)
## [1] 3.600 1.800 3.333 2.283 4.533 2.883
summary(duration)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.600   2.163   4.000   3.488   4.454   5.100
head(rinh_chit)
## [1] 79 54 74 62 85 55
summary(rinh_chit)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    43.0    58.0    76.0    70.9    82.0    96.0

5. Summary dữ liệu

summary(my_data)
##    eruptions        waiting    
##  Min.   :1.600   Min.   :43.0  
##  1st Qu.:2.163   1st Qu.:58.0  
##  Median :4.000   Median :76.0  
##  Mean   :3.488   Mean   :70.9  
##  3rd Qu.:4.454   3rd Qu.:82.0  
##  Max.   :5.100   Max.   :96.0

6. Tính phân vị

quantile(duration, c(0.25, 0.32, 0.5, 0.75))
##     25%     32%     50%     75% 
## 2.16275 2.39524 4.00000 4.45425
quantile(rinh_chit, c(0.25, 0.32, 0.5, 0.75))
##   25%   32%   50%   75% 
## 58.00 62.72 76.00 82.00

7. Biểu đồ Box gì gì đó nhìn khá oách

boxplot(duration,
        horizontal = TRUE,
        main = "Boxplot of Eruption Duration",
        ylab = "Duration (minutes)",
        col = "lightblue")

boxplot(rinh_chit,
        horizontal = TRUE,
        main = "Boxplot of Waiting Time",
        ylab = "Waiting (minutes)",
        col = "lightgreen")

boxplot(my_data,
        horizontal = TRUE,
        main = "Boxplot of Faithful Dataset",
        col = c("lightblue", "lightgreen"))