Let's say I have these files:
N1.xlsx
N2.xlsx
N3.xlsx
N4.xlsx
I want them in a list, but each dataframe must be named according to the file it was read from, like
mylist =
N1
N2
N3
N4
I'm using:
fnames = mixedsort(sort(list.files("filepath", pattern = '*.xlsx', full.names = F)))
mylist <- lapply(fnames, function(x) {
read_xlsx(paste0(x), col_names = TRUE)
})
But this code creates a list without identification
mylist =
[[1]]
[[2]]
[[3]]
[[4]]
Its important to keep the names of each file in each dataframe, so I can export them correctly later!
You could name mylist
with the names you already have in fnames
.
names(mylist) <- tools::file_path_sans_ext(fnames)
mylist
file_path_sans_ext
remove extension from the filenames.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments