I have 30 dataframes called Z1 to Z30. I want to run a function on each of them. How can I run it using a vector of dataframes names paste0("Z", 1:30)
?
Asked
Active
Viewed 29 times
0
-
You may use functions like `Map` or `purrr::map` – iago Sep 02 '21 at 13:17
-
2If they are all similarly structured, I suggest you change your methodology to a [list of tables](https://stackoverflow.com/a/24376207/3358227), at which point `lapply(my_list_of_frames, function(z) {...})` is all you would need. – r2evans Sep 02 '21 at 13:19
-
Please provide enough code so others can better understand or reproduce the problem. – Community Sep 02 '21 at 13:40
-
2You can get `my_list_of_frames` mentioned in @r2evans comment using `my_list_of_frames <- mget(paste0("Z", 1:30))` which is also mentioned in the same answer. – Ronak Shah Sep 02 '21 at 13:40
-
Thank you all! List of tables could be helpful but basically get() and mget() functions was all I needed. Thank you @RonakShah – Natalia Słomka Sep 02 '21 at 13:51
-
Just a hint: avoid `get()` + `assign()` structures. If you are going to do something like this, use a list instead. – Martin Gal Sep 02 '21 at 14:21
-
@MartinGal why should I avoid using get() and assign()? – Natalia Słomka Sep 02 '21 at 19:55