Learn R Programming

retrosheet (version 1.0.2)

getRetrosheet: Import single-season retrosheet data as a structured R object

Description

This function downloads and parses data from http://www.retrosheet.org for the game-log, event, (play-by-play), roster, and schedule files.

Usage

getRetrosheet(type, year, team, schedSplit = NULL, stringsAsFactors = FALSE, ...)

Arguments

type
character. This argument can take on either of "game" for game-logs, "play" for play-by-play (a.k.a. event) data, "roster" for team rosters, or "schedule" for the game schedule for the given year.
year
integer. A valid four-digit year.
team
character. Only to be used if type = "play". A single valid team ID for the given year. For available team IDs for the given year call getTeamIDs(year). The available teams are in the "TeamID" column.
schedSplit
One of "Date", "HmTeam", or "TimeOfDay" to return a list split by the given value, or NULL (the default) for no splitting.
stringsAsFactors
logical. The stringsAsFactors argument as used in data.frame. Currently applicable to types "game" and "schedule".
...
further arguments passed to download.file.

Value

The following return values are possible for the given type
  • game - a data frame of gamelog data for the given year
  • play - a list, each element of which is a single game's play-by-play data for the given team and year. Each list element is also a list, containing the play-by-play data split into individual matrices.
  • roster - a named list, each element containing the roster for the named team for the given year, as a data frame.
  • schedule - a data frame containing the game schedule for the given year

Examples

Run this code
## get the full 1995 season schedule
getRetrosheet("schedule", 1995)
## Not run: 
# ## get the same schedule, split by time of day
# getRetrosheet("schedule", 1995, schedSplit = "TimeOfDay")
# 
# ## get the roster data for the 1995 season, listed by team
# getRetrosheet("roster", 1995)
# 
# ## get the full gamelog data for the 2012 season
# getRetrosheet("game", 2012)
# 
# ## get the play-by-play data for the San Francisco Giants' 2012 season
# getRetrosheet("play", 2012, "SFN")
# ## End(Not run)

Run the code above in your browser using DataLab