我在一个文件夹中有 100 个 excel 文件,我想将每个文件的第四列的名称更改为 R 中相应的文件名。
1 回答
1
filenames <- list.files(pattern = '\\.xlsx', full.names = TRUE)
lapply(filenames, function(x) {
#Read the data
data <- readxl::read_excel(x)
#Change the 4th column with filename
names(data)[4] <- tools::file_path_sans_ext(basename(x))
#Write the data back
writexl::write_xlsx(data, x)
})
于 2021-05-31T07:59:19.187 回答