HS/HSL R Workshop Live Code


Loading external data

  1. Excel
    install the gdata library

    install.packages("gdata")
  2. load gdata library

    library("gdata")
  3. show documentation for reading Excel with foreign library

    help(read.xls)
  4. read first worksheet of Excel file into variable excelData

    excelData <- read.xls("Desktop/data.xlsx")
  5. view excelData

    View(excelData)
  6. SPSS data
    load the built-in foreign library

    library(foreign)
  7. show documentation for reading SPSS with foreign library

    help(read.spss)
  8. load SPSS file into SPSSdata variable

    SPSSdata = read.spss("Downloads/Robbery Incident.sav", to.data.frame=TRUE)
  9. view SPSSdata

    View(SPSSdata)
  10. CSV data from web
    show documentation for reading table data with the built-in read.csv function

    help(read.csv)
  11. load online csv file into webCSV variable
    lets find a CSV file online together and copy the URL to the command below

    webCSV <- read.csv("https://raw.githubusercontent.com/BobAdamsEE/SouthParkData/master/Season-11.csv")
  12. view webCSV

    View(webCSV)