Learn R Programming

TouRnament (version 0.2.5)

leaguetable: Create a league table

Description

Create a table for sports (soccer) leagues by individually defined criteria from a results dataset.

Usage

leaguetable(dataset, home, away, score_home, score_away, date, date_start,
  date_end, matchday, matchday_start, matchday_end, points = c(3, 1, 0),
  rank_by = c("GD", "GF"), HA_display = FALSE, DC_display = FALSE)

Arguments

dataset

A dataset with the results.

home

Name of the home team variable in the dataset as a character string.

away

Name of the away team variable in the dataset as a character string.

score_home

Name of the home team goals variable in the dataset as a character string.

score_away

Name of the away team goals variable in the dataset as a character string.

date

Name of the date variable in the dataset as a character string (optional).

date_start

Earliest date to include if not the earliest date in the dataset as a character string in the format "YY-mm-dd" (optional).

date_end

Last date to include if not the last date in the dataset as character string in the format "YY-mm-dd" (optional).

matchday

Name of the matchday variable in the dataset as a character string (optional).

matchday_start

Earliest matchday to include if not the earliest in the dataset as an integer (optional).

matchday_end

Last matchday to include if not the last in the dataset as an integer (optional).

points

Vector of integers of length three containing the points awarded for wins, draws and losses. Defaults to c(3,1,0).

rank_by

Character vector with the order of arguments to sort the league table following "Pts". Defaults to c("GD","GF").

HA_display

Logical value to indicate whether home and away results should be displayed in the table. Defaults to FALSE.

DC_display

Logical value to indicate whether direct comparison variables from ranking vector should be displayed in the table. Defaults to FALSE.

Value

League table in the form of a data.frame.

Details

Mandatory input is a dataset with match results and the names of the variables for home and away team and their respective scored goals.

List of abbreviations:

  • A = Away (used only as appendix "_A"),

  • D = (Matches) Drawn,

  • DC = Direct comparison (used only as appendix "_DC"),

  • GA = Goals against,

  • GD = Goal difference,

  • GF = Goals for,

  • H = Home (used only as appendix "_H"),

  • L = (Matches) Lost,

  • P = (Matches) Played,

  • Pos = Position,

  • Pts = Points,

  • W = (Matches) Won.

Possible ranking criteria are:

  • D = (Matches) Drawn,

  • GA = Goals against,

  • GD = Goal difference,

  • GF = Goals for,

  • L = (Matches) Lost,

  • P = (Matches) Played,

  • Pts = Points (Automatically set as most important ranking criterium, doesn't need to be set),

  • W = (Matches) Won

as well as any of the above with the appendix "_DC", for example Pts_DC or GD_DC, which will applied as ranking criteria for teams with an equal number of points (Pts).

Please be aware that ranking for all criteria is done with descending order. So GA or L can technically be used for ranking, but will result in nonsensical results.

Further optional parameters are the point rewards for wins, draws and losses,the display of additional columns with separate home and away tables and the dates and matchdays to be used for calculation.

If a date range and a matchday range are set, the subset of matches that fit both selection criteria will be used for calculation.

Examples

Run this code
# NOT RUN {
#league table for La Liga 94/95 with three point rewards (instead of two) and home and away results
require(engsoccerdata)
leaguetable(dataset=engsoccerdata::spain[which(engsoccerdata::spain$Season==1994),],
home="home", away="visitor",score_home="hgoal", score_away="vgoal", date="Date",
points = c(3,1,0), rank_by = c("Pts_DC","GD_DC","GF_DC","GD","GF"), DC_display = TRUE)
# }

Run the code above in your browser using DataLab