Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper function to manually add latest results to dataframe #44

Closed
JoGall opened this issue Oct 15, 2017 · 1 comment
Closed

Helper function to manually add latest results to dataframe #44

JoGall opened this issue Oct 15, 2017 · 1 comment

Comments

@JoGall
Copy link
Contributor

JoGall commented Oct 15, 2017

Just posting a helper function for manually adding new results to the results dataframe in case you want to include it in the package. I often find myself wanting to analyse the latest results before the football-data.co.uk CSVs have been updated so this comes in handy. It uses the matchTeamnames() function described here.

addResult <- function(home, visitor, hgoal, vgoal, Date = Sys.Date(), division = 1, tier = 1, Season = 2017) {
  
  home <- matchTeamnames(home)
  visitor <- matchTeamnames(visitor)
  
  FT <- paste0(hgoal, "-", vgoal)
  totgoal <- hgoal + vgoal
  goaldif <- hgoal - vgoal
  result <- ifelse(hgoal > vgoal, "H", ifelse(hgoal < vgoal, "A", "D"))
  
  df <- data.frame(Date, Season, home, visitor, FT, hgoal, vgoal, division, tier, totgoal, goaldif, result)
  
  rbind(england, df) %>% 
    arrange(Date)
}

Example usage:

addResult("Man City", "Stoke", 7, 2, Sys.Date() - 1) %>% 
  tail(2)

#             Date Season             home    visitor  FT hgoal vgoal division tier totgoal goaldif result
#194110 2017-10-01   2017 Newcastle United  Liverpool 1-1     1     1        1    1       2       0      D
#194111 2017-10-14   2017  Manchester City Stoke City 7-2     7     2        1    1       9       5      H
@jalapic
Copy link
Owner

jalapic commented Oct 24, 2020

using the _current() functions to basically do this.

@jalapic jalapic closed this as completed Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants