Field_Goals_Made <- c(18, 7, 6, 9, 10,13)
Field_Goals_Attempted <- c(36, 23, 12, 18, 24,22)
Field_Goals_pct <- Field_Goals_Made / Field_Goals_Attempted
Field_Goals_pct
## [1] 0.5000000 0.3043478 0.5000000 0.5000000 0.4166667 0.5909091
average_Field_Goals_pct <- mean(Field_Goals_pct)
average_Field_Goals_pct
## [1] 0.4686539
Average field goal percentage: 0.4687 or 46.87%
Consider the following vectors in R representing the number of three-pointers made (3PM) and attempted (3PA) by a basketball player over a seven-game span:
Three_Pointers_Made <- c(3, 5, 10, 6, 3, 7, 1)
Three_Pointers_Attempted <- c(9, 10, 18, 12, 11, 12, 11)
Calculate both the average of the individual per-game three-point percentages and the overall (cumulative) three-point shooting percentage across all seven games. Submit your code and knitted R HTML file or RPubs link as instructed.
three_pt_pct <- Three_Pointers_Made / Three_Pointers_Attempted
three_pt_pct
## [1] 0.33333333 0.50000000 0.55555556 0.50000000 0.27272727 0.58333333 0.09090909
# Average of the individual per-game percentages
average_pct <- mean(three_pt_pct)
average_pct
## [1] 0.4051227
# Overall (cumulative) percentage: total makes / total attempts
overall_pct <- sum(Three_Pointers_Made) / sum(Three_Pointers_Attempted)
overall_pct
## [1] 0.4216867
Average of individual per-game percentages: 0.4051 or 40.51%
Overall cumulative percentage: 0.4217 or 42.17%
PlayerID <- c(1, 2, 3, 4, 5)
Hits <- c(112, 124, 121, 106, 140)
AtBats <- c(400, 450, 380, 500, 402)
HR <- c(25, 22, 8, 20, 11)
BB <- c(50, 60, 19, 150, 55)
SO <- c(60, 65, 67, 92, 70)
players <- data.frame(PlayerID, Hits, AtBats, HR, BB, SO)
# Calculate OBP
players$OBP <- (players$Hits + players$BB) / (players$AtBats + players$BB)
players
# Identify the player with the highest OBP
players[which.max(players$OBP), ]
Player 5 has the highest OBP 42.67%