Excel sheets can be imported into R by the help of xlsx package. The function to be used is read.xlsx() and following is the syntax:
file – path to the excel workbook/file
n – number of worksheet in the excel file that needs to be imported
(note: a) the first line of the excel sheet needs to contain the variable names b) you can save the path to the excel file in an object and then write the object name in the read.xlsx function)
the code would look like this
myxfile <- “c:/myxfile.xlsx”
myxdataframe <- read.xlsx(myxfile, 1)
Explanation: the first line loads the xlsx package in R, the second line stores the path to the file named myxfile in an object called myxfile and the third line imports the first worksheet of the excel file named myxfile into a data frame.