Load data “sleep” from package “datasets”

library(datasets)
data("sleep")

(a) Summary of data

summary(sleep)
##      extra        group        ID   
##  Min.   :-1.600   1:10   1      :2  
##  1st Qu.:-0.025   2:10   2      :2  
##  Median : 0.950          3      :2  
##  Mean   : 1.540          4      :2  
##  3rd Qu.: 3.400          5      :2  
##  Max.   : 5.500          6      :2  
##                          (Other):8
  • From the summary table, we can see that:
  1. The extra hour min value is 5.5, while max hour is 5.5. Their mean value is 1.54 . (numbers here are represented by inline r syntax)
  2. The group numbers are evenly distributed in 1 and 2. There are 10 observations in group 1 and 10 obs in group 2.
  3. The ID numbers are also evenly distributed from 1 to 10. There are two observations in all of 1 to 10 values.

(b) Plot the graph

  • Plot the students’ extra sleep hour distribution by group:
plot(sleep$extra~sleep$group,
     main = "Students extra sleep hour distribution by group",
     xlab = "Group", ylab = "Sleep Hour", 
     col = c("yellow","blue")
     )