#Question_1: Compute the log base 5 of 10 and the log of 10.

log(5)
## [1] 1.609438
log(10)
## [1] 2.302585

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

BA=(42)/(212)
BA
## [1] 0.1981132

#Question_3:Compute the OBP for a player with the following general stats: #AB=565,H=156,BB=65,HBP=3,SF=7

AB <- 565
H <- 156
BB <- 65
HBP <- 3
SF <- 7


OBP <- (H + BB + HBP) / (AB + H + BB + HBP + SF)

OBP
## [1] 0.281407

#Question_4: Define two vectors,runs_per_9innings and hits_per_9innings, each with five elements.

runs_per_9innings <- c(3, 2, 4, 5, 1)


hits_per_9innings <- c(7, 8, 6, 9, 5)


runs_per_9innings
## [1] 3 2 4 5 1
hits_per_9innings
## [1] 7 8 6 9 5

#Question_5: Get the first element of hits_per_9innings.

first_element <- hits_per_9innings[1]


first_element
## [1] 7

#Question_6: Get the last element of hits_per_9innings.

last_element <- hits_per_9innings[length(hits_per_9innings)]

last_element
## [1] 5

#Question_7: Find the most frequent value of hits_per_9innings.

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


most_frequent_hits <- getMode(hits_per_9innings)


most_frequent_hits
## [1] 7

#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

survey_responses <- c("Saturday", "Saturday", "Sunday", "Monday", "Saturday", "Tuesday", "Sunday", "Friday", "Friday", "Monday")


survey_summary <- table(survey_responses)


survey_summary
## survey_responses
##   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.

most_frequent_survey_answer <- getMode(survey_responses)


most_frequent_survey_answer
## [1] "Saturday"