In: Math
2. The data set `MLB-TeamBatting-S16.csv` contains MLB Team Batting
Data for selected variables. Load the data set from the given url
using the code below. This data set was obtained from [Baseball
Reference](https://www.baseball-reference.com/leagues/MLB/2016-standard-batting.shtml).
* Tm - Team
* Lg - League: American League (AL), National League (NL)
* BatAge - Batters’ average age
* RPG - Runs Scored Per Game
* G - Games Played or Pitched
* AB - At Bats
* R - Runs Scored/Allowed
* H - Hits/Hits Allowed
* HR - Home Runs Hit/Allowed
* RBI - Runs Batted In
* SO - Strikeouts
* BA - Hits/At Bats
* SH - Sacrifice Hits (Sacrifice Bunts)
* SF - Sacrifice Flies
Using the `mlb16.data` data, do the following:
i) use `filter` to select teams with the following arguments:
a) Cardinals team `STL`.
b) teams with Hits `H` more than 1400 last 2016 season.
c) team league `Lg` is National League `NL`.
ii) use `arrange` to select teams in decreasing number of home runs
`HR`.
iii) use `arrange` to display the teams in decreasing number of
`RBI`.
iv) use `group_by` to group the teams per league; and `summarise`
to compute the average `RBI` within each league. Use the pipe
`%>%` operator to string multiple functions.
### Code chunk
```{r}
# load the data set
mlb16.data <-
read.csv("https://raw.githubusercontent.com/jpailden/rstatlab/master/data/MLB-TeamBatting-S16.csv")
str(mlb16.data) # check structure
head(mlb16.data) # show first six rows
# last R code line
```