R – Importing Excel file – R for Statistics
Information sourced from: https://datatofish.com/import-excel-r/
Install package and load library:
# Install package if required: install.packages("readxl") # Make sure package is loaded: library("readxl")
Use ‘read_excel’ to read the file.
# 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")
AND…. This site: https://appsilon.com/r-and-excel/ discusses some extra points such as specifying range and also using ‘BERT’ from Excel to access R functionality from Excel
Alternatively, use copy/paste to move data from Excel to R:
DataVar <- read.delim("clipboard", sep = "\t")
As discussed here: https://www.analyticsvidhya.com/blog/2023/03/top-3-ways-to-import-data-into-r-using-copy-and-paste/