The first thing to do is to install the package readxl
, using the
install.packages("readxl")
This step only needs to be done once. With the readxl
package installed, you need to load it into memory through the
library(readxl)
This step needs to be done every time R (or RStudio) is closed and then reopened.
The path
argument is the path to the .xls file on your computer. For example, when I run path <- readxl_example("datasets.xls")
on my PC, the result is
path
[1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/readxl/
extdata/datasets.xls"
Probably the result on your computer will be different, but realize that it will also have .xls
, as this is the address of the readxl
sample dataset file. To read all the sheets in an .xls file, run the
planilhas <- lapply(excel_sheets(path), read_excel, path = path)
length(planilhas)
The first line will read all the spreadsheets within an .xls file and save them within an object called planilhas
. The second command will tell you how many spreadsheets were in this file. Now just run
planilhas[2]
For example, to see what data is present in worksheet 2 of the .xls file read.
Editing after this comment :
You can create a different date frame for each element of the planilhas
list via the
for (j in 1:length(planilhas)){
assign(paste("planilha", j, sep=""), planilhas[[j]])
}