Chapter 26 Loading Excel spreadsheets into RStudio

Nathan Brouwer, Phd
brouwern at gmail.com
https://github.com/brouwern
Twitter: lobrowR

THIS CHAPTER HAS NOT BEEN WRITTEN

re-save as .csv and load

load directly

In this walk through we first re-save this data in an R-compatible format, a “csv” file, called “Lab1_data_PA_eagles.csv”.

26.0.1 Prepping data in Excel

26.0.1.1 Save data to your R working directory (WD)

Find the file https://github.com/brouwern/wildlifeR/tree/master/inst/extdata

Save the file “Lab1_data_PA_eagles.xlsx” to your computers desktop. Today we will be using this as the “working directory”

26.0.1.2 Re-Save The Excel file as a “csv” file

In Excel, follow these steps

  • “File”
  • “Save As”
  • “Browse”
  • Select the working directory (your desktop)
  • Select “Save as type”
  • Select “CSV (Comma delimited)”
  • Click “Save”

The data is now in a format that can be loaded into R.

26.1 Preparing a file for loading into R

Things work best when your Excel file is “clean” & only has exactly what you want in it. Any extra, accidental typing can cause problems or make things confusing. A good practice is to always highlight cells to the right of and below your data, right click & select “Delete”. This will remove any accidental typing that occurred. Do this to the cells below your data also.

26.2 Reload data

Reload data; be sure to include the “csv” at the end. Use this code “eaglesPA <- read.csv(file =”eaglesPA.xlsx”)“. NOTE: I changed the name of the file to include”_w_2_states” so that I wouldn’t overwrite the original file. Don’t use this code unless you changed the file name to the exact same thing

#Use this code, w/o the "#" in front of it
# eaglesPA <- read.csv(file = "eaglesPA.xlsx")

#NOTE: I changed the name of the file to include "_w_2_states" so that I wouldn't overwrite the origina file.  Don't use this code unless you changed the file name to the exact smame thing
#eaglesPA <- read.csv(file = "./data/Lab1_data_PA_eaglesPA_w_2_states.csv")

Type ls() to see what is now in your workspace

ls()
## [1] "eaglesPA"     "image.file"   "lynx"         "lyxn.df"      "par.default" 
## [6] "par.mar"      "sunspot.year" "x.lim"

Look at the re-loaded eaglesPA data object

summary(eaglesPA)
dim(eaglesPA)
head(eaglesPA)
tail(eaglesPA)