Basketball = read.table(file = "https://raw.githubusercontent.com/Jlok17/Data-Science-Projects/main/nba_players_19.csv",header = TRUE, sep = ',')
df <- data.frame(Basketball)
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(stringr)
Basketball_Alt <- df %>% unite(Name, c("first_name","last_name" ), sep = ' ', remove = TRUE)
alt <- Basketball_Alt$height/12
Basketball_Alt['height'] <- alt
Basketball_Alt <- Basketball_Alt %>% rename(Height_FT = height, Team = team, Team_Abbr. = team_abbr, Position = position, Player_Number = number)
Basketball_Alt$Position <- str_replace(string=Basketball_Alt$Position, pattern="Forward-Center", replacement="FC")
Basketball_Alt$Position <- str_replace(string=Basketball_Alt$Position, pattern="Forward-Guard", replacement="FG")
Basketball_Alt$Position <- str_replace(string=Basketball_Alt$Position, pattern="Center-Forward", replacement="CF")
Basketball_Alt$Position <- str_replace(string=Basketball_Alt$Position, pattern="Guard-Forward", replacement="GF")
Basketball_Alt %>% filter(Position == 'Guard', Team_Abbr. == 'OKC' ) -> Basketball_Guard
Basketball_Alt %>% filter(Position == 'Forward' ) -> Basketball_Forward
Basketball_Alt %>% filter(Position == 'FG' ) -> Basketball_FG
Basketball_Alt %>% filter(Position == 'FC' ) -> Basketball_FC
Basketball_Alt %>% filter(Position == 'Center' ) -> Basketball_Center
Basketball_Alt %>% filter(Position == 'CF' ) -> Basketball_CF
Basketball_Alt %>% filter(Position == 'GF' ) -> Basketball_GF
head(Basketball_Alt)
## X Name Team Team_Abbr. Position Player_Number Height_FT
## 1 1 Alex Abrines Thunder OKC Guard 8 6.500000
## 2 2 Jaylen Adams Hawks ATL Guard 10 6.166667
## 3 3 Steven Adams Thunder OKC Center 12 7.000000
## 4 4 Bam Adebayo Heat MIA CF 13 6.833333
## 5 5 DeVaughn Akoon-Purcell Nuggets DEN GF 23 6.500000
## 6 6 LaMarcus Aldridge Spurs SAS Forward 12 6.916667
summary(Basketball_Alt$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 5.750 6.417 6.583 6.588 6.833 7.250
summary(Basketball_Guard$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.083 6.167 6.417 6.333 6.458 6.583
summary(Basketball_GF$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.417 6.500 6.500 6.544 6.583 6.833
summary(Basketball_Center$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.750 6.917 7.000 6.964 7.000 7.250
summary(Basketball_CF$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.750 6.833 6.833 6.858 6.896 7.000
summary(Basketball_Forward$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.417 6.667 6.750 6.726 6.833 7.083
summary(Basketball_FC$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.667 6.833 6.917 6.913 7.000 7.250
summary(Basketball_FG$Height_FT)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 6.333 6.500 6.500 6.523 6.583 6.667
ggplot(Basketball_Guard, aes(Height_FT))+ geom_bar() +labs(title = "Heights of NBA Guard", x = "Height in Feet", Y = "Number of NBA Players") + theme(plot.title = element_text(hjust = 0.5))
ggplot(Basketball_Center, aes(Height_FT))+ geom_bar() +labs(title = "Heights of NBA Centers", x = "Height in Feet", Y = "Number of NBA Players") + theme(plot.title = element_text(hjust = 0.5))
ggplot(Basketball_Forward, aes(Height_FT))+ geom_bar() +labs(title = "Heights of NBA Forward", x = "Height in Feet", Y = "Number of NBA Players") + theme(plot.title = element_text(hjust = 0.5))
ggplot(Basketball_Alt,aes(Position,Height_FT)) + geom_boxplot() + labs(title = "Heights of NBA by Position") + theme(plot.title = element_text(hjust = 0.5))
Analysis: As seen Above, the average height of a standard Forward, Center, Guard is 6.75, 7, and 6.417 Feet Respectively. Since there are hybrid roles where a forward can play as a center and guard additionally or a center as a forward or guard as a forward, there are certain characteristics. For an example Forwards who has a hybrid roles as a guard are shown to be on average shorter than a traditional guard from 6.5 Feet as a hybrid compared to 6.75 Feet as a traditional. As this is statistical data, there are intangibles that can’t be shown in this data set as for skill level and team chemistry.