Question 1: This is the sixth season of outfielder Juan Soto in the majors. If during the first five seasons he received 79, 108, 41, 145, and 135 walks, how many does he need on this season for his overall number of walks per season to be at least 100?
# Walks so far
walks_before <- c(79, 108, 41, 145, 135)
# Average number of walks per season wanted
wanted_walks <- 100
# Number of seasons
n_seasons <- 6
# Needed walks on season 6
x_6 <- n_seasons*wanted_walks - sum(walks_before)
# Minimum number of walks needed by Juan
x_6
## [1] 92
Juan Soto will need 92 walks for his overall number of walks per season to be at least 100. We can confirm this number by finding the mean.
soto_walks <- c(79, 108, 41, 145, 135, 92)
mean(soto_walks)
## [1] 100
Question 2: The average salary of 7 basketball players is 102,000 dollars a week and the average salary of 9 NFL players is 91,000. Find the mean salary of all 16 professional players.
n_1 <- 7
n_2 <- 9
y_1 <- 102000
y_2 <- 91000
salary_ave <- (n_1*y_1 + n_2*y_2)/(n_1+n_2)
salary_ave
## [1] 95812.5
The mean salary of all 16 professional players is $95,812.50.
Question 3: Use the triples_hit.csv file
triples_length <- read.table("triples_hit.csv", header = TRUE, sep = ",")
triple_hits <- triples_length$triples_hit
# mean
triples_mean <- mean(triple_hits)
triples_mean
## [1] 4.96
# median
triples_median <- median(triple_hits)
triples_median
## [1] 5
# number of observations
triples_n <- length(triple_hits)
triples_n
## [1] 100
# standard deviation
triples_sd <- sd(triple_hits)
triples_sd
## [1] 2.884721
# percentage of observation within one standard deviation of the mean
triples_w1sd <- sum((triple_hits - triples_mean)/triples_sd < 1)/ triples_n
triples_w1sd
## [1] 0.88
# difference from empirical
triples_w1sd - 0.68
## [1] 0.2
# within 2 sd
triples_w2sd <- sum((triple_hits - triples_mean)/triples_sd < 2)/ triples_n
triples_w2sd
## [1] 0.93
# difference from empirical
triples_w2sd - 0.95
## [1] -0.02
# within 3 sd
triples_w3sd <- sum((triple_hits - triples_mean)/triples_sd < 3)/ triples_n
triples_w3sd
## [1] 0.98
# difference from empirical
triples_w3sd - 0.9973
## [1] -0.0173
hist(triple_hits, main = "Histogram of Triples Hit", xlab = "Triples Hit",col = "grey",border = "white", xlim = c(0,14), ylim = c(0,35))