How to import an excel file or a sheet in R?

862    Asked by Tanyaverma in Data Science , Asked on Nov 9, 2019
Answered by Tanya verma

To import excel file we have to install a library called ‘readxl’

install.packages(“readxl”)

library(readxl)

Excel file can contain two formats

Xls and xlsx.To read both the formats we can do the following

# read_excel reads both xls and xlsx files

df=read_excel("my-spreadsheet.xls")

df=read_excel("my-spreadsheet.xlsx")

Not only reading the file, we can also read the file with a particular sheet name or sheet number.

# Specify sheet with a number or name

df=read_excel("my-spreadsheet.xls", sheet = "sheet1") df=read_excel("my-spreadsheet.xls", sheet = 5)



Your Answer

Interviews

Parent Categories