5
I want to import 27 Excel tables into R without having to type 27 times the import command already, that the table names go from tab101
to tab127
. I tried that way, but you made a mistake:
library(readxl)
n = c()
for (i in 1:27){ # fazendo um vetor com os nomes dos arquivos
a = "tab"
a = paste(a, 100+i, sep = "")
a = paste(a, ".xls", sep = "")
n[i] = a
}
t =lapply(n, read_excel) #aplicando read_excel para importar cada arquivo e
#juntando tudo em uma lista
Until then I thought I was successful. The list of 27 elements is created, but when I ask to display the first element of the list the following appears:
t[1]
[[1]]
Error in gsub(ansi_regex, "", string, perl = TRUE) :
input string 1 is invalid UTF-8
If I call the str(t)
it shows that the data were imported correctly. I am not knowing how to access each element of the list. But the real focus is to be able to import all tables at once, you don’t necessarily have to create a list with them. I tried to do just with the for, putting the read_table(a)
inside, but doing nothing.
Thank you very much, Marcus. I managed to solve it in another way, but yours was much more succinct and direct, besides presenting me some new commands. Very good
– Érika SM
Marcus, and if some worksheets have multiple worksheets. How to import all worksheets and all worksheets they have?
– Érika SM
Érika, put your solution here too. see, read_excel(path, sheet = 1), then you should give to vary the sheet with a second for.
– Márcio Mocellin