0

I have many dataframes with weekly data and whose names follow a sequence like this: df1, df2, df3...dfN.

The point is that I have to execute one function in all of these dataframes, so I would like to create a loop to apply the function to them. I understand that the best way would be to join all of them in a list and use lapply. However, my functions belong to a specific package that only works with dataframes.

Any solution? Thank you very much for your help!!

  • When you join all of them in a list each element is still a dataframe so your function should still work when you apply it using `lapply`. – Ronak Shah Sep 08 '20 at 03:12
  • How did you create all these variables in the first place? Having variables with indexes in their names is a bad code smell in R. It would probably be better to store the data frames in a list and then you can apply whatever function you want to each element of the list. You really should provide a more specific [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we can provide the best possible suggestion. – MrFlick Sep 08 '20 at 03:13
  • It might be helpful to read https://stackoverflow.com/a/24376207/3358272. – r2evans Sep 08 '20 at 03:16
  • Google search something like `R apply function to list of data frames` and many useful responses will come up. Applying functions to list elements is regarded as a basic skill in R programming. – Paul van Oppen Sep 08 '20 at 03:23

0 Answers0