In this shot, we will go over how to use the read_excel() method to read an Excel file in R. The read_excel() method is used to read an Excel file. In order to use this method, you first have to import the readxl library in your R program.
install.packages("readxl")library("readxl")path of the file to the read_excel() methoddata <- read_excel("dataset.xlsx")print(data)read_excel("path",sheet=1,col_names= TRUE,col_types=NULL,na="",skip= 0)
path: Directory or path of excel file.sheet: Either the name of the sheet in the Excel file or index number. The default is 1.col_names: Default is TRUE.
TRUE: Read the first row as a file header.FALSE: File does not have a header.Character Vector: A character vector that contains header names.col_types: Default is NULL.
NULL: Detects the type of column from the spreadsheet.Vector: A vector that contains “blank”, “numeric”, “date”, or “text.”na: Keeps empty cells as is, but we can specify na to fill empty cells. The default is "".skip: Number of rows to skip from start before reading a file. The default is 0.# Install readxl package if not availableinstall.packages("readxl")library("readxl") # library for read_excel() methoddata <- read_excel("dataset.xlsx")print(data)
Xlsx or Xls file, we can use the read_excel() method from the readxl package (lines 1 and 2). We specify the necessary parameters like path_name or file_name, if the program and file are in the same directory.read_excel() method.The code above provides dataset.xlsx as an argument file and produces the following output.