I am relatively new to R and I am working on creating one dataframe out of many .csv files that I have in different subfolders of the same folder. Thus far, I've got this:
setwd("~/LMB/Top 6 - 2019/Juegos")
Batting.files <- list.files(path = "~/LMB/Top 6 - 2019/Juegos/",
recursive = T, pattern=c("(statsHomeBatting.csv|statsVisitorBatting.csv)",
full.names=T))
setwd("~/LMB/Top 6 - 2019/Juegos/")
Batting.Logs <- do.call(rbind,lapply(Batting.files,read.csv, check.names = FALSE, sep = ";"))
The subfolders where I have the files look like this:
~\LMB\Top 6 - 2019\Juegos\Lanús at Ferro Feb 10
What I'd like is to have a variable in each column (let's name it Batting.Logs$Game
where it shows the last part of the directory (in this case Lanús at Ferro Feb 10
)
I have searched through old answers but I have not been able to get it done, so I am now unsure that it can be done with the current coding I have.
Thanks in advance!