ToMatchShape: Convert a Schedule, Hybrid, or MatchResults data frame to...

Description Usage Arguments Details Value See Also Examples

View source: R/firstapiR_util.R


The firstapiR functions GetSchedule(), GetHybridSchedule(), and GetMatchResults return a data frame in team shape, i.e., with one team listed in every row, and six rows per match. R documentation often refers to data frames in this format as narrow data frames. ToMatchShape will convert these narrow data frames to a wide data frame (it's wide because it has more columns) with all six teams listed in one row and only one row per match.





A firstapiR data frame. The data frame must inherit from the schedule, hybridSchedule, or emphmatchResults class data frames that are returned by firstapiR functions. The data frame must also be in team shape and have the shape attribute set to "team".


ToMatchShape will only convert data frames that are in team shape, with their shape attribute set to "team". To convert a data frame that is in alliance shape to match shape, first use ToTeamShape() to convert the data frame back to team shape, and then use ToMatchShape() to convert it to match shape.

FirstapiR proivdes functions to reshape data frames because different shapes are useful for different purposes. For example, team shape is useful for extracting data for a single team because it's only necessary to subset the data frame on the team column. Match shape is useful for displaying schedules. Alliance shape is useful for calculating offensive power rating (OPR).

This function throws an error if df does not inherit from matchResults, schedule, or hybridSchedule, or if the data frame's shape attribute is missing or is anything other than team.


A data frame of class matchResults, schedule, or hybridSchedule (depending on the class of the df argument) in match shape, with the shape attribute set to "match".

See Also

GetMatchResults, GetHybridSchedule, GetSchedule


sn <- GetSession("myUserName", "key", season = 2016)
matchResults_teamshape <- GetMatchResults(sn, event = "PNCMP")
matchResults_matchshape <- ToMatchShape(matchResults_teamshape)

irwinsnet/FIRST_api_R documentation built on May 17, 2017, 4:23 a.m.