-
Notifications
You must be signed in to change notification settings - Fork 4
/
HW3.Rmd
67 lines (53 loc) · 1.74 KB
/
HW3.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: "NBA 2014-2015球季 各隊分析"
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
##把資料讀進來的程式碼
```{r echo=T}
if (!require('SportsAnalytics')){
install.packages("SportsAnalytics")
library(SportsAnalytics)
}
NBA1415<-fetch_NBAPlayerStatistics("14-15")
```
##各隊最辛苦的球員
依據各隊總上場時間(分鐘)最多的球員
```{r echo=T}
MaxMinutesPlayed<-aggregate(TotalMinutesPlayed~Team,NBA1415,max)
NBA1415MaxMinutesPlayed<-merge(NBA1415,MaxMinutesPlayed)
output<-NBA1415MaxMinutesPlayed[order(NBA1415MaxMinutesPlayed$TotalMinutesPlayed,decreasing = T),c("Team","Name","TotalMinutesPlayed")]
library(knitr)
kable(output, digits=2)
```
##各隊得分王
依據各隊總得分最高之球員
```{r echo=T}
MaxPoint<-aggregate(TotalPoints~Team,NBA1415,max)
NBA1415MaxPoint<-merge(NBA1415,MaxPoint)
output<-NBA1415MaxPoint[order(NBA1415MaxPoint$TotalPoints,decreasing = T),c("Team","Name","TotalPoints")]
library(knitr)
kable(output, digits=2)
```
##各隊最有效率的球員
依據各隊員(總得分/出戰分鐘數)最高之球員
```{r echo=T}
NBA1415$effcient<- NBA1415$TotalPoints / NBA1415$TotalMinutesPlayed
Maxeffcient<-aggregate(effcient~Team,NBA1415,max)
NBA1415Maxeffcient<-merge(NBA1415,Maxeffcient)
output<-NBA1415Maxeffcient[order(NBA1415Maxeffcient$effcient,decreasing = T),c("Team","Name","effcient")]
library(knitr)
kable(output, digits=2)
```
##各隊三分球出手最準的球員
依據(三分出手命中/三分出手次數) 最高之球員
```{r echo=T}
NBA1415$accuracy<- NBA1415$ThreesMade / NBA1415$ThreesAttempted
Maxaccuracy<-aggregate(accuracy~Team,NBA1415,max)
NBA1415Maxaccuracy<-merge(NBA1415,Maxaccuracy)
output<-NBA1415Maxaccuracy[order(NBA1415Maxaccuracy$accuracy,decreasing = T),c("Team","Name","accuracy")]
library(knitr)
kable(output, digits=2)
```