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

Description Usage Arguments Details Value See Also Examples

View source: R/firstapiR_util.R

Description

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. The functions ToMatchShape and ToAllianceShape will convert data frames in the narrow team shape to the wide (they're called wide because they have more columns) alliance or match shapes. ToTeamShape converts these wide data frames back to narrow data frames in team shape.

Usage

1

Arguments

df

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

Details

ToTeamShape will only convert data frames that are in match or alliance shape, with their shape attribute set to match or alliance.

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.

Value

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

See Also

GetMatchResults, GetHybridSchedule, GetSchedule

Examples

1
2
3
4
sn <- GetSession("myUserName", "key", season = 2016)
matchResults_teamshape <- GetMatchResults(sn, event = "PNCMP")
matchResults_matchshape <- ToMatchShape(matchResults_teamshape)
matchResults_back_to_teamshape <- ToTeamShape(matchResults_matchshape)

irwinsnet/FIRST_api_R documentation built on Dec. 22, 2020, 5:12 p.m.