Consider the following vectors representing the number of field goals made and attempted by a basketball player in five games: Field Goals Made: c(18, 7, 6, 9, 10,13) Field Goals Attempted: c(36, 23, 12, 18, 24,22). Calculate the field goal percentage for each game and select the correct average field goal percentage for the five games.
# Create the vectors
FGM = c(18, 7, 6, 9, 10,13)
FGA = c(36, 23, 12, 18, 24,22)
FGM
## [1] 18 7 6 9 10 13
FGA
## [1] 36 23 12 18 24 22
# Field Goal Percentage Equation
## The output displays the field goal percentage for each game.
FGP = FGM / FGA
FGP
## [1] 0.5000000 0.3043478 0.5000000 0.5000000 0.4166667 0.5909091
# Field Goal Percentage Average for the 5 games
FGP_avg = mean(FGP)
FGP_avg
## [1] 0.4686539
The average Field Goal Percentage (FGP) for the 5 games is 0.468 (0.47 is rounded).
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.
TPM = c(3, 5, 10, 6, 3, 7, 1)
TPM
## [1] 3 5 10 6 3 7 1
TPA = c(9, 10, 18, 12, 11, 12, 11)
TPA
## [1] 9 10 18 12 11 12 11
# Individual Per Game three point percentages
# TPP = Three Point Percentage
TPP = TPM / TPA
TPP
## [1] 0.33333333 0.50000000 0.55555556 0.50000000 0.27272727 0.58333333 0.09090909
Please see output above for Three Point Percentage per game.
# TPP cumulative average of all games
TPP_avg = mean(TPP)
TPP_avg
## [1] 0.4051227
Please see the output above for the cumulative average of all 7 games.
Consider the following dataset representing the performance of baseball players in a season. It includes the following variables: PlayerID, Hits, At-Bats, Home Runs (HR), Walks (BB), and Strikeouts (SO).
PlayerID Hits At-Bats HR BB SO
1 112 400 25 50 60
2 124 450 22 60 65
3 121 380 8 19 67
4 106 500 20 150 92
5 140 402 11 55 70
Compute the On-Base Percentage (OBP) for each player and select the player with the highest OBP. Submit your code and knitted R HTML file or RPubs link as instructed.
(Formula: OBP = (Hits + Walks) / (At-Bats + Walks))
Player = c(1,2,3,4,5)
Hits = c(112, 124, 121, 106, 140)
At_Bat = 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)
Hits
## [1] 112 124 121 106 140
At_Bat
## [1] 400 450 380 500 402
HR
## [1] 25 22 8 20 11
BB
## [1] 50 60 19 150 55
SO
## [1] 60 65 67 92 70
OBP = (Hits + BB) / (At_Bat / BB)
OBP
## [1] 20.25000 24.53333 7.00000 76.80000 26.67910
The output above displays the OBP for each player.
OBP_max = max(OBP)
OBP_max
## [1] 76.8
The player with the highest OBP is Player 4.