I am combining one sheet from all XLS files in a folder into one data frame & displaying a specific range from all of them, which works fine. However, I want to add the file name as an actual column, which isn't working right now - it displays as rows without adding a column.
A screenshot may help me make more sense. You can see that the 2nd 2 columns have headers but the first does not, so if I add in functionality to export to Excel etc. that column will be missing.
Code:
#library
library(readxl)
library(plyr)
#define path
# setwd
my_path <- file.path("C:", "File", "Path")
setwd(my_path)
# list all files in the directory
data.files = list.files()
# list all files in the directory ending with .xls
wb <- list.files(pattern = "*.xls")
# create an empty list
dflist <- list()
# populate dflist with wb
for (i in wb){
dflist[[i]] = data.frame(read_excel(i, sheet = "Sheet1", range = "C15:D16", col_names = FALSE, row.names(data.files)))
}
#create final data frame, bind dflist
OBJDList = do.call(what = rbind, args = dflist)