Getting Data into R Excel Files

1) The best way to read in Excel Files is to use the read_excel function that's in the readxl library.

2) To download the readxl library, we first have to install it. We can do this by typing: install.packages("readxl")

3) That will run some code in your R Console and will take a few seconds to install. You will need the internet for this since we are downloading a new library. Once it is done, the code will be installed to your computer.

4) In order to make the functions in the readxl package available for use in this session, you will have to use the library function (with the package name not in quotes): library(readxl)

5) Now, we have at our disposal a whole bunch of new functions specifically geared towards working with Excel. Keep the library() function in your script.

6) Now that readxl loaded, we can read data into R from an Excel file by typing: menu<-read_excel("http://joeystanley.com/downloads/menu.xlsx",sheet=2)

7) You can optionally specify which sheet of the file to read in by adding sheet=2 within the parenthesis. Otherwise R will assume the first sheet within the Excel worksbook.

8) There another way to read in data that does not involve typing long path names. You can use the file.choose command instead. When you do this, a window will open up and you will be able to find your file and click on it just like you were opening any other file. For MAC computers, type: menu<-file.choose(). For Windows/PC, type: menu<-choose,file()