NBA = read.csv("NBA_train.csv")
str(NBA)
'data.frame': 835 obs. of 20 variables:
$ SeasonEnd: int 1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 ...
$ Team : chr "Atlanta Hawks" "Boston Celtics" "Chicago Bulls" "Cleveland Cavaliers" ...
$ Playoffs : int 1 1 0 0 0 0 0 1 0 1 ...
$ W : int 50 61 30 37 30 16 24 41 37 47 ...
$ PTS : int 8573 9303 8813 9360 8878 8933 8493 9084 9119 8860 ...
$ oppPTS : int 8334 8664 9035 9332 9240 9609 8853 9070 9176 8603 ...
$ FG : int 3261 3617 3362 3811 3462 3643 3527 3599 3639 3582 ...
$ FGA : int 7027 7387 6943 8041 7470 7596 7318 7496 7689 7489 ...
$ X2P : int 3248 3455 3292 3775 3379 3586 3500 3495 3551 3557 ...
$ X2PA : int 6952 6965 6668 7854 7215 7377 7197 7117 7375 7375 ...
$ X3P : int 13 162 70 36 83 57 27 104 88 25 ...
$ X3PA : int 75 422 275 187 255 219 121 379 314 114 ...
$ FT : int 2038 1907 2019 1702 1871 1590 1412 1782 1753 1671 ...
$ FTA : int 2645 2449 2592 2205 2539 2149 1914 2326 2333 2250 ...
$ ORB : int 1369 1227 1115 1307 1311 1226 1155 1394 1398 1187 ...
$ DRB : int 2406 2457 2465 2381 2524 2415 2437 2217 2326 2429 ...
$ AST : int 1913 2198 2152 2108 2079 1950 2028 2149 2148 2123 ...
$ STL : int 782 809 704 764 746 783 779 782 900 863 ...
$ BLK : int 539 308 392 342 404 562 339 373 530 356 ...
$ TOV : int 1495 1539 1684 1370 1533 1742 1492 1565 1517 1439 ...
# Vectors
made <- c(4, 5, 3, 6, 7)
attempted <- c(9, 10, 8, 11, 12)
# Calculate shooting percentage per game
percentage <- (made / attempted) * 100
# Print individual percentages
print(percentage)
[1] 44.44444 50.00000 37.50000 54.54545 58.33333
# Calculate average shooting percentage over five games
average_percentage <- mean(percentage)
# Print average
print(average_percentage)
[1] 48.96465
#The average three-point shooting percentage over the five games is approximately 48.96%.