Importing Excel file – R for Statistics

Information sourced from: https://datatofish.com/import-excel-r/

Install package: install.packages("readxl")

Make sure package is selected: library("readxl")

Use ‘read_excel’  to read the file:
read_excel("Path where your Excel file is stored\\File Name.xlsx",sheet = "Your sheet name")

Alternatively, set the working directory as the location where the file is located and omit the filepath so only the filename is required.

Assign it to a variable like this:
data_set = read_excel("Path where your Excel file is stored\\File Name.xlsx",sheet = "Your sheet name")

NOTE: Excel file needs to be closed for R to open the file.

Together:

# Only run 'install' when/if needed
# install.packages("readxl")
library("readxl")
read_excel("File_Path\\File_Name.xlsx",sheet = "Sheet_Name")

# Or...set to desired variable
data_set = read_excel("File_Path\\File_Name.xlsx",sheet = "Sheet_Name")

Leave a Reply

Your email address will not be published.