0

I am trying to create a for loop to cycle through multiple data frames doing the same thing for each set. Below is an example of what I am trying to do but I get the error:

Error

  target of assignment expands to non-language object

generating code

for (k in 1:6) {
  get(paste0("df.",k))$YrQtr <- paste0(format(Sys.Date()-months(1),format="%Y"),quarters((Sys.Date()-months(1))))
      get(paste0("df.",k))$SetID <- k
}
Pax
  • 664
  • 4
  • 23
  • Please use `dput()` or `dput(head())` to post a copy of your data to make your issue reproducible. And it's better if you post the script part of your question using the code block function. Thanks – L Tyrone Mar 20 '23 at 22:25
  • Why not create a list of data frames use the relevant apply function? – John Garland Mar 20 '23 at 23:20
  • list of frames: https://stackoverflow.com/a/24376207/3358227, then use `lapply` (or `Map`) – r2evans Mar 21 '23 at 02:31

0 Answers0