# Addition

2+3
## [1] 5
4-3
## [1] 1
2*5
## [1] 10
2*3-1+7
## [1] 12
log(10)# ln()
## [1] 2.302585
log10(10)
## [1] 1
log10(100)
## [1] 2
#Question_1: Compute the log base 5 of 10 and the log of 10.

logb(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)
BA
## [1] 0.1981132
Batting_Average=round(BA,digits = 3)
Batting_Average
## [1] 0.198

The Batting average would be 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

The OBP would be 0.281

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

runs_per_9innings <- c(32, 22, 30, 44, 10)
runs_per_9innings
## [1] 32 22 30 44 10
hits_per_9innings <- c(15, 27, 36, 58, 62)
hits_per_9innings
## [1] 15 27 36 58 62

Comment : I picked five elements to define my vectors.

#Question_5: Get the first element of hits_per_9innings.

hits_per_9innings[1]
## [1] 15
#Question_6: Get the last element of hits_per_9innings.
# Getting Last elements in 2 forms
hits_per_9innings[5]
## [1] 62
hits_per_9innings[length(hits_per_9innings)]
## [1] 62
#Question_7: Find the most frequent value of hits_per_9innings.

# Function to find the mode, i.e. most frequent value
getMode <- function(x) {
     ux <- unique(x)
     ux[which.max(tabulate(match(x, ux)))]
}

getMode(hits_per_9innings)
## [1] 15
#Comment write our own function to get frequent value in order to retrieve output. 
#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

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

table(submitted_survey)
## submitted_survey
##   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(submitted_survey)
## [1] "Saturday"