4.3 Introduction to data.table

Load the data.table package.

library("data.table")


Turn the variable "pitching" (downloaded in Quiz 2.2) into a data.table (also called "pitching")

pitching = as.data.table(pitching)


Show the first five rows of the "pitching" data.table

pitching[1:5, ]


Extract the "playerID" column of the "pitching" data.table

pitching$playerID


Filter the "pitching" data.table to include only rows where the teamID is "OAK"

pitching[teamID == "OAK", ]


Filter the "pitching" data.table to include only rows where the column G (that's the number of games the pitcher played) is greater than or equal to 10.

pitching[G >= 10, ]


How many rows are in this filtered dataset (those that have 10 or more games)?

29624


Sort the pitching data.table in ascending order by year (you don't need to save the result to a variable).

pitching[order(yearID), ]