Import an Excel file / .xslx file in R
Import an excel file in R with the xlsx package
The importation of an excel isn't natively possible in R, for a .xls or a .xslx file. Thankfully, the XLSX library is here.
Unlike .csv file import in R with read.csv(), you have to load (and install) the xlsx library before to import your excel file. Here is how import your excel file in R and associate it to an object of your environment.
myDataset <- read.xlsx("myFile.xlsx")
Your object myDataset will contain the values of your excel file. So, it's possible to manipulate and process your data with your R script.
Advanced features of read.xlsx()
To go further, the read.xlsx() function have several parameters for your needs. Here are the main parameters:
sheet = 1 # The name or the number of the sheet you want to read
startRow = 1 # The number of the first row to read
colNames = TRUE # TRUE by default, set the first row as the header of the dataset
rowNames = FALSE # FALSE by default, set the first column for the name of the line
You can adapt this function to explore more complex excel files.