I want to import 27 Excel tables into R without typing the import command 27 times, since table names range from tab101
to tab127
. I tried this way, but got wrong:
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
So far as I thought it was successful. The list of 27 elements is created, but when I ask to show 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
Being that if I call the str(t)
it shows that the data has been imported correctly. I'm not sure how to access each element in the list. But the very focus is on being able to import all tables at once, you do not necessarily have to create a list with them. I tried to do only with for, putting read_table(a)
in, but did nothing.