(Use the R studio to find the answer.)
5. Consider the Batting data frame from the Lahman library.
a) How many observations and how many variables does Batting contain?
(b) Use filter from the dplyr library to make a new data frame with just the information from yearID 2015. How many observations does this contain?
(c) Who had the most Bases on Balls (BB) in 2015? (You can just give the player ID)
(d) How many players had more than 100 BB in 2015?
a)
Ran the R code dim(Batting) to get the below output.
[1] 105861 22
Number of observations = 105861
Number of variables = 22
b)
Load the library dplyr as below.
library(dplyr)
Using filter from the dplyr library to make a new data frame with just the information from yearID 2015
Batting.2015 = filter(Batting, yearID == '2015')
dim(Batting.2015)
[1] 1486 22
Number of observations this contains = 1486
c)
Ran the below R script to get the player Id of most Bases on Balls (BB) in 2015
filter(Batting.2015, BB == max(Batting.2015$BB))$playerID
[1] "vottojo01"
The player Id with the most Bases on Balls (BB) in 2015 is vottojo01.
d)
Number of players had more than 100 BB in 2015 is 5.
> dim(filter(Batting.2015, BB >
100))
[1] 5 22
Get Answers For Free
Most questions answered within 1 hours.