Suppose we have files 2021-02.csv, 2021-2.csv, ... , and 2021-12.csv in directory C:/R/month_data and we want to read them all into separate data frames but replacing original names with months' names (eg. 2021-01.csv should turn into "jan", 2021-02.csv into "feb", ..., 2021-12.csv into "dec").
The aim of the code is to have a total of 12 dfs.
I've written the following code:
filenames = list.files(path = "C:/R/month_data",
pattern = "2021-+.*csv")
names = substr(filenames,1,7)
months = c("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec")
for(i in names){
for (j in months){
filepath = file.path("C:/R/month_data",paste(i,".csv",sep=""))
assign(j, read.csv(filepath))
}
}
The code technically runs but it doesn't associate the month number (eg. 2021-04) with the rigth month name (eg. "apr")
What should I do?

