Question 1
log(10, base = 5)
## [1] 1.430677
log(10)
## [1] 2.302585
Question 2
BA <- 42 / 212
BA
## [1] 0.1981132
Batting_Average <- round(BA, digits = 3)
Batting_Average
## [1] 0.198
Question 3
OBP <- (156 + 65 + 3) / (565 + 65 + 3 + 7)
OBP
## [1] 0.35
On_Base_Percentage <- round(OBP, digits = 3)
On_Base_Percentage
## [1] 0.35
Question 4
runs_per_9innings <- c(4, 3, 5, 2, 4)
hits_per_9innings <- c(8, 10, 7, 8, 9)
runs_per_9innings
## [1] 4 3 5 2 4
hits_per_9innings
## [1] 8 10 7 8 9
Question 5
hits_per_9innings[1]
## [1] 8
Question 6
hits_per_9innings[length(hits_per_9innings)]
## [1] 9
Question 7
getMode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
getMode(hits_per_9innings)
## [1] 8
Question 8
game_day <- c(
"Saturday",
"Saturday",
"Sunday",
"Monday",
"Saturday",
"Tuesday",
"Sunday",
"Friday",
"Friday",
"Monday"
)
table(game_day)
## game_day
## Friday Monday Saturday Sunday Tuesday
## 2 2 3 2 1
Question 9
getMode(game_day)
## [1] "Saturday"