Exercise 2.

rep("mouse", 3)
## [1] "mouse" "mouse" "mouse"
rep(1,5)
## [1] 1 1 1 1 1
rep(5,1)
## [1] 5
c(rep("a", 4),rep("b", 2), rep("c", 5))
##  [1] "a" "a" "a" "a" "b" "b" "c" "c" "c" "c" "c"
error_data <- c(rep(0, 41), rep(1, 30), rep(2, 15),  rep(3, 8), rep(4, 5))

hist(error_data, breaks = c(seq(from = -0.5, 4.5, by = 1)), xlab = "Defects", main = "Number of Defects", labels = TRUE, ylim = c(0, 50))

Histogram with Corrected Code333

number_of_defects <- c(rep(0, 41), rep(1, 31), rep(2, 15), rep(3, 8), rep(4, 8))

hist(number_of_defects, breaks = c(seq(from = -1, 4, by = 1)), xlab = "Defects", main = "Number of Defects", labels = TRUE, ylim = c(0,50))

number_of_defects <- c(rep(0, 41), rep(1, 31), rep(2, 15), rep(3, 8), rep(4, 8))

hist(number_of_defects, breaks = c(seq(from = -1, 4, by = 1)), xlab = "Defects", main = "Number of Defects", labels = TRUE, ylim = c(0,30))

error.data = c(rep(0,41), rep(1,31), rep(2,15), rep(3,8), rep(4,5))

hist(error.data, breaks = c(seq(from = -0.5, 4.5, by =1)), xlab = "defects", main = "Number of Defects", labels = TRUE, ylim = c(0,50))

mean(error.data)
## [1] 1.05
median(error.data)
## [1] 1
sd(error.data)
## [1] 1.157976
boxplot(error.data, horizontal = TRUE, xlab = "Number of Defects")