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

log(10, base <- 5)
## [1] 1.430677
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)
print(BA)
## [1] 0.1981132
Batting_Average <- round(BA, digits <- 3)
Batting_Average
## [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)
OBP
## [1] 0.281407
On_Base_Percentage<-round(OBP,digits <- 3)
On_Base_Percentage
## [1] 0.281
#Question_4: Define two vectors,runs_per_9innings and hits_per_9innings, each with five elements.

# Define the vectors
runs_per_9innings <- sample(1:10, 5, replace <- TRUE)
hits_per_9innings <- sample(1:10, 5, replace <- TRUE)

# Print the vectors to check the elements
print(runs_per_9innings)
## [1] 7 7 4 6 3
print(hits_per_9innings)
## [1] 4 2 2 7 6
#Question_5: Get the first element of hits_per_9innings.

length(hits_per_9innings)
## [1] 5
hits_per_9innings[1]
## [1] 4
#Question_6: Get the last element of hits_per_9innings.

hits_per_9innings[5]
## [1] 6
#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] 2
#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)

print(survey_summary)
## survey_responses
##   Friday   Monday Saturday   Sunday  Tuesday 
##        2        2        3        2        1
# Create the vector of survey responses
survey_responses <- c("Saturday", "Saturday", "Sunday", "Monday", "Saturday", "Tuesday", "Sunday", "Friday", "Friday", "Monday")

# Create a table summarizing the responses
survey_summary <- table(survey_responses)

# Convert the table to a data frame
survey_summary_df <- as.data.frame(survey_summary)

# Sort the data frame by the count (Frequency) in descending order
sorted_survey_summary_df <- survey_summary_df[order(-survey_summary_df$Freq), ]

# Print the sorted summary
print(sorted_survey_summary_df)
##   survey_responses Freq
## 3         Saturday    3
## 1           Friday    2
## 2           Monday    2
## 4           Sunday    2
## 5          Tuesday    1
#Question_9: What is the most frequent answer recorded in the survey? Use the getMode function to compute results.

freqAnswer <- getMode(survey_responses)
freqAnswer
## [1] "Saturday"