0

From the baseballr package

batting_orders <- map_dfr(games, get_batting_orders)

So the games is a vector for every unique game, and I was wondering if I could attach each game ID that I'm giving as an input in map_dfr, to the outputting dataframe.

I tried to create a function, but it wont take a vector as an input.

  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 21 '23 at 13:18
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 21 '23 at 16:10

1 Answers1

1

Yes, map_dfr has an argument for it: .id; you just have to give an name and the input value is automatically added to your data.frame:

batting_orders <- map_dfr(games, get_batting_orders, .id = "game_id")
starja
  • 9,887
  • 1
  • 13
  • 28