---
title: "Assignment 6"
author: "By Andrew Helbig"
date: "5/13/2020"
output: html_document
---
##R packages
library(tidyverse)
library(dbplyr)
#A 'dplyr' back end for databases that allows you to work with remote database tables as if they are in-memory data frames. Basic features works with any database that has a 'DBI' back end; more advanced features require 'SQL' translation to be provided by the package author.This package allows you to do sql commands in r, very good for making graphs looks cleanner and other analytical functions
library(skimr)
#he package's API is tidy, functions take data frames, return data frames and can work as part of a pipeline. The returned skimr object is subsettable and offers a human readable output. Easier for cleaning up datasets , ane performing other analytical functions.
library(stringr)
#A consistent, simple and easy to use set of wrappers around the fantastic 'stringi' package. All function and argument names (and positions) are consistent, all functions deal with "NA"'s and zero length vectors in the same way, and the output from one function is easy to feed into the input of another.
library(sqldf)
#This is package is used for more sql functions so you can build graphs or run functions easier
library(DT)
#This package is good for creating data tables with all the information in your dataframe.
library(knitr)
#General Purpose for Dynamci Reports
library(XML)
library(rvest)
library(RCurl)
library(magrittr)
library(httr)
library(writexl)
library(readr)
## [1] 1
## Rk Player Pos Age Tm G GS MP FG FGA FG% 3P 3PA 3P%
## 1 1 Steven Adams C 26 OKC 58 58 27.0 4.5 7.6 .591 0.0 0.1 .333
## 2 2 Bam Adebayo PF 22 MIA 65 65 34.4 6.3 11.1 .567 0.0 0.2 .077
## 3 3 LaMarcus Aldridge C 34 SAS 53 53 33.1 7.4 15.0 .493 1.2 3.0 .389
## 4 4 Nickeil Alexander-Walker SG 21 NOP 41 0 12.2 1.9 5.5 .339 1.0 2.9 .342
## 5 5 Grayson Allen SG 24 MEM 30 0 16.6 2.6 5.9 .449 1.1 3.0 .363
## 6 6 Jarrett Allen C 21 BRK 64 58 25.7 4.2 6.5 .646 0.0 0.1 .000
## 2P 2PA 2P% eFG% FT FTA FT% ORB DRB TRB AST STL BLK TOV PF PTS
## 1 4.5 7.6 .593 .593 1.9 3.2 .590 3.4 6.0 9.4 2.4 0.9 1.1 1.5 1.9 10.9
## 2 6.3 10.9 .576 .568 3.6 5.3 .690 2.5 8.0 10.5 5.1 1.2 1.3 2.8 2.5 16.2
## 3 6.2 12.0 .519 .532 3.0 3.6 .827 1.9 5.5 7.4 2.4 0.7 1.6 1.4 2.4 18.9
## 4 0.9 2.7 .336 .427 0.4 0.7 .607 0.2 1.8 2.0 1.8 0.3 0.2 1.0 1.1 5.1
## 5 1.5 2.8 .541 .543 1.0 1.2 .857 0.2 2.0 2.2 1.4 0.2 0.0 0.8 1.2 7.4
## 6 4.2 6.4 .654 .646 2.3 3.7 .620 3.0 6.4 9.5 1.3 0.6 1.3 1.1 2.3 10.6
#Cleaning up the data
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
## Warning: NAs introduced by coercion
#I had to change the stats I wanted to run analysis on from characters to numbers. So could get better results on y visualizations
#Data Dictionary Rk – Rank Pos – Position Age – Player’s age on February 1 of the season Tm – Team G – Games GS – Games Started MP – Minutes Played Per Game FG – Field Goals Per Game FGA – Field Goal Attempts Per Game FG% – Field Goal Percentage 3P – 3-Point Field Goals Per Game 3PA – 3-Point Field Goal Attempts Per Game 3P% – FG% on 3-Pt FGAs. 2P – 2-Point Field Goals Per Game 2PA – 2-Point Field Goal Attempts Per Game 2P% – FG% on 2-Pt FGAs. FG% – Effective Field Goal Percentage. This statistic adjusts for the fact that a 3-point field goal is worth one more point than a 2-point field goal. FT – Free Throws Per Game FTA – Free Throw Attempts Per Game FT% – Free Throw Percentage ORB – Offensive Rebounds Per Game DRB – Defensive Rebounds Per Game TRB – Total Rebounds Per Game AST – Assists Per Game STL – Steals Per Game BLK – Blocks Per Game TOV – Turnovers Per Game PF – Personal Fouls Per Game PTS – Points Per Game
#About this document
#Question 1 ### Who are the players who average more than 15 points per game and are younger than 22 years old?
#The results show 42 players who are younger than 22 in the NBA and who average more than 20 results. If your a die hard sport fan for a team with one of these player, you will be trying to by merchandise of these players. So the NBA teams need to make merchandise of these players since they are the future of the NBA and can make the NBA a lot of money. For the Team that has these player, they need to try to keep as my as these players as possible after there rookie contract is up. Since these players will be stars, they will ask for a lot of money or they will go to a team that pays them, so teams need to get ready to make offers based off the players are perfroming. Plus the more of these players the nba is able to keep, the more the franchise and fans like the player! For a future statistical analysis, you would uses point per game as well as other stats to correlate how much the person is worth. You could use points and other factors as the key factors and see what players in a correlated analysis are your ideal players based on the key metrics you chose.
#Question 2
##What players are shoot over 40% from 3 point and o 40% from 2 point range plus take at least 5 three pointers a game.
| Player | FG. | X3P. | X3PA |
|---|---|---|---|
| Malik Beasley | 0.472 | 0.426 | 8.2 |
| Dāvis Bertāns | 0.434 | 0.424 | 8.7 |
| Bojan Bogdanović | 0.447 | 0.414 | 7.3 |
| Seth Curry | 0.500 | 0.453 | 5.1 |
| Evan Fournier | 0.470 | 0.406 | 6.7 |
| Danilo Gallinari | 0.439 | 0.409 | 7.3 |
| Tim Hardaway Jr. | 0.437 | 0.407 | 7.2 |
| Joe Harris | 0.471 | 0.412 | 5.9 |
| Khris Middleton | 0.499 | 0.418 | 5.8 |
| Marcus Morris | 0.433 | 0.410 | 5.9 |
| Marcus Morris | 0.442 | 0.439 | 6.1 |
| Sviatoslav Mykhailiuk | 0.410 | 0.404 | 5.1 |
| J.J. Redick | 0.450 | 0.452 | 6.4 |
| Duncan Robinson | 0.467 | 0.448 | 8.4 |
| Terry Rozier | 0.423 | 0.407 | 6.7 |
| Karl-Anthony Towns | 0.508 | 0.412 | 7.9 |
#This results show very good shooters in the NBA. As it is hard to have at least a 40% average from 2 & 3 and while taking at least 5 three pointers a game. This shows players who you might want to recruit if you have a low percentage shooting team. As by simply adding one of these people can open up your shooting game vs opponnets. I would use regressions in the future to see these attributes translate into winning/losing percentage for teams.
#Question 3
#What players averaged over 1 assist per game and over 2 blocks per game?
| Player | AST | BLK |
|---|---|---|
| Robert Covington | 1.3 | 2.5 |
| Anthony Davis | 3.1 | 2.4 |
| Rudy Gobert | 1.5 | 2.0 |
| Jonathan Isaac | 1.4 | 2.4 |
| Brook Lopez | 1.6 | 2.4 |
| Kristaps Porziņģis | 1.7 | 2.1 |
| Myles Turner | 1.1 | 2.2 |
| Hassan Whiteside | 1.2 | 3.1 |
| Player | X3P. | FT. | FG. |
|---|---|---|---|
| Amir Coffey | 0.143 | 0.333 | 0.394 |
| Jarrett Culver | 0.299 | 0.462 | 0.404 |
| Brandon Knight | 0.297 | 0.308 | 0.326 |
| Vic Law | 0.000 | 0.000 | 0.000 |
| Thabo Sefolosha | 0.278 | 0.375 | 0.407 |
| Kenrich Williams | 0.260 | 0.375 | 0.343 |
#Question 5
#What NBA has the highest pts per game and how many 3 pointer do they take average?
| Tm | PTS | X3P. |
|---|---|---|
| HOU | 34.4 | 0.352 |
| WAS | 30.5 | 0.353 |
| MIL | 29.6 | 0.306 |
| ATL | 29.6 | 0.361 |
| POR | 28.9 | 0.394 |
| DAL | 28.7 | 0.318 |
| HOU | 27.5 | 0.254 |
| BRK | 27.4 | 0.394 |
| LAC | 26.9 | 0.366 |
| LAL | 26.7 | 0.335 |
| MIN | 26.5 | 0.412 |
| PHO | 26.1 | 0.360 |
| LAL | 25.7 | 0.349 |
| CHI | 25.5 | 0.380 |
| NOP | 24.3 | 0.387 |
| UTA | 24.2 | 0.364 |
| GSW | 23.6 | 0.374 |
| TOR | 23.6 | 0.359 |
| BOS | 23.6 | 0.398 |
| NOP | 23.6 | 0.462 |
| PHI | 23.4 | 0.348 |
| TOT | 23.1 | 0.367 |
| POR | 22.5 | 0.380 |
| MIN | 22.4 | 0.331 |
| SAS | 22.2 | 0.267 |
| TOT | 21.8 | 0.332 |
| MIN | 21.7 | 0.345 |
| ATL | 21.6 | 0.401 |
| BOS | 21.2 | 0.377 |
| MIL | 21.1 | 0.418 |
| LAC | 21.0 | 0.399 |
| GSW | 20.8 | 0.245 |
#The results show that if you want to average the most points per game you need to shoot the take the most 3 point tries. This isn’t surprizing since 3 is worth more than 2 points, but these shots have a weaker % of going in. So is the lower prercentage shot worth it taking more of? In the future, a good statistical analysis would be to see if this correlates to wins in game overall.