Question 1: Compute the log base 5 of 10 and the log of 10.

log(10, base = 5)
## [1] 1.430677
log10(10)
## [1] 1

Question 2: What is the batting average of a player that bats 42 hits in 212 at bats?

BA=(42/212)
Batting_Avg=round(BA, digits = 3)
BA
## [1] 0.1981132
Batting_Avg
## [1] 0.198

Question 3: Compute the OBP for a player with the following general stats:

#AB=565,H=156,BB=65,HBP=3,SF=7

OBP=(156+65+3)/(565+156+65+3+7)
On_Base_Percentage=round(OBP, digits = 3)
OBP
## [1] 0.281407
On_Base_Percentage
## [1] 0.281

Question 4: Define two vectors,runs_per_9innings and hits_per_9innings, each with five elements.

runs_per_9innings <- c(8, 10, 9, 7, 12)
runs_per_9innings
## [1]  8 10  9  7 12
hits_per_9innings <- c(6, 9, 5, 7, 10)
hits_per_9innings
## [1]  6  9  5  7 10

Question 5: Get the first element of hits_per_9innings

hits_per_9innings[1]
## [1] 6

Question 6: Get the last element of hits_per_9innings.

hits_per_9innings[length(hits_per_9innings)]
## [1] 10

Question 7: Find the most frequent value of hits_per_9innings.

getMode <- function(x) {
     ux <- unique(x)
     ux[which.max(tabulate(match(x, ux)))]
}
getMode(hits_per_9innings)
## [1] 6

Question 8: Summarize the following survey with the `table()` command:

What is your favorite day of the week to watch baseball? A total of 10 fans submitted this survey.

Saturday, Saturday, Sunday, Monday, Saturday,Tuesday, Sunday, Friday, Friday, Monday

Fav_Gameday <- c("Saturday", "Saturday", "Sunday", "Monday", "Saturday", "Tuesday", "Sunday", "Friday", "Friday", "Monday")
table(Fav_Gameday)
## Fav_Gameday
##   Friday   Monday Saturday   Sunday  Tuesday 
##        2        2        3        2        1

Question 9: What is the most frequent answer recorded in the survey? Use the getMode function to compute results.

getMode(Fav_Gameday)
## [1] "Saturday"