How to Read Data From Excel in R

03.29.2021

R provides many convient ways to read data from files into memory. One common way is to read data from excel files. In this article, we will learn how to read data from Excel into R.

To read data from Excel, we will need to use the read.xlsx method from the openxlsx library. Let's see an example.

library(openxlsx)

df = read.xlsx(xlsxFile = 'data.xlsx',
                 sheet = 'sheet1')

In the above, we pass the name of the file and the sheet that we want to parse. We can also load the entire work book using the following:

library(openxlsx)

wb = loadWorkbook("data.xlsx")

Then, if the workbook is welled straucture, we can extra all the tables using the getTables function.

tables = getTables(wb, 'shee1')