To import excel file, you can use read_excel() function from readxl package.

The following method shows how you can do it with syntax.

Method: Use read.excel() function

library("readxl")

df = read_excel("file.xlsx")

The following example shows how to use read_excel() function in R.

Import Excel File Using read_excel() Function

Let’s see example how to import excel file in R:

# Install package
install.packages("readxl")

# Import library
library("readxl")

# Read data from excel
df=read_excel("cylinder.xlsx")

# print excel data
print(df)

Output:

  Cylinder  Value
  <chr>     <dbl>
1 cylinder1    12
2 cylinder2    10
3 cylinder3    13
4 cylinder4    14

The output shows data from cylinder.xlsx file.

Here we pass excel file name instead of file path to read data from excel file.Also we can see when we print this excel file data it specify datatype of each column.