0

I would like to save different data frames in R that is titled with a year. My approach so far has been to do like this:

year <- 2020
write.table(df, file = "D:/.../.../df_year.xlsx")

If I am using the above approach, I am ending with a data frame called df_year.xlsx, but I want it to be named "df_2020.xlsx".

danlooo
  • 10,067
  • 2
  • 8
  • 22
JosL
  • 7
  • 3

1 Answers1

0

There is the glue package (Part of the tidyverse) for this:

library(stringr)
year <- 2020
write.table(df, file = str_glue("D:/.../.../df_{year}.xlsx"))

Alternatively, one can use paste:

write.table(df, file = paste0("D:/.../.../df_", year, ".xlsx"))
danlooo
  • 10,067
  • 2
  • 8
  • 22