Reputation: 505
I have 18 files(.xls) in list and I want to read them in one go
Here is my codes below:
filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif")
df.list=lapply(filenames, function(x) read_excel(file = x,sheetIndex = 1,as.data.frame = TRUE,header = TRUE))
it did not work
Could you please tell me what I have done wrong and how I should do it?
Upvotes: 1
Views: 4021
Reputation: 41
You can use the same code with some changes. Under read_excel:
Then,
filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif")
df.list=lapply(filenames, function(x) read_excel(x,sheet = 1,header = TRUE))
Then to convert it into a data.frame format, use the below
Appending of all the different data into one master data
master_file = as.data.frame(do.call(rbind,df.list))
Upvotes: 4
Reputation: 276
Can you simply try a loop?
filenames=list.files("C:/Users/ozgur.alptekin/Downloads/elif")
for (i in 1:length(filenames) {
assign(paste0("file_", i),
read_excel(file = filenames[i],sheetIndex = 1, as.data.frame = TRUE, header = TRUE), envir = .GlobalEnv)
}
reply if it works.
Upvotes: 2