JaseZiv / worldfootballR

A wrapper for extracting world football (soccer) data from FBref, Transfermark, Understat
https://jaseziv.github.io/worldfootballR/
444 stars 60 forks source link

Issue with fotmob_get_match_players(): needs match and player-team information #105

Closed mattbarger closed 2 years ago

mattbarger commented 2 years ago

Hello and thank you for this package.

I was running the fotmob_get_match_players() function for a vector of matches. When I received the resulting dataframe, I am unable to distinguish which players play for which teams. While I scramble for a workaround, I want to let you know it would be incredibly useful and convenient to ascribe a match id and a team id to each player observation returned by this function.

Thanks again, Matt

tonyelhabr commented 2 years ago

It's a good suggestion to add match_id and team_id to the output.

You can add match_id yourself with the current state of the package like this.

library(dplyr)
library(purrr)
c(3609987, 3609979) %>% 
  setNames(., .) %>% 
  map_dfr(fotmob_get_match_players, .id = "match_id") %>% 
  mutate(across(match_id, as.integer))

Or like this.

library(dplyr)
library(tibble)
library(tidyr)
tibble(
  match_id = c(3609987, 3609979)
) %>% 
  mutate(
    match = map(match_id, fotmob_get_match_players)
  )

I'll have to check on team_id. I agree that this would be convenient to have in the output.

JaseZiv commented 2 years ago

Thanks for your help @tonyelhabr.

I will mark this closed with the release of v0.5.1.3000. Install it using devtools::install_github("JaseZiv/worldfootballR")

Reach out if you need a hand with anything else @mattbarger

mattbarger commented 2 years ago

Awesome, thanks guys!

mattbarger commented 2 years ago

Also, Just a quick Q on this: the code you showed matches match_id, which feels straightforward.... but what about team_id? when I pull fotmob_get_match_players() I don't get the team each player is on... just who played the game.

I know you're working on it, just let me know what you come up with! Thanks again.

mattbarger commented 2 years ago

Okay, I think found it. If it helps, the variable is_home_team provides a T/F key for the home/away team.

mutate(team_id = ifelse(is_home_team == TRUE, home_team_id, away_team_id)

JaseZiv commented 2 years ago

fotmob_get_match_players

As mentioned, with the most recent version, the output data frame contains a column for team_id.

Install using:

devtools::install_github("JaseZiv/worldfootballR")