Reading sheets

Introduction to Importing Data in R

Filip Schouwenaars

Instructor, DataCamp

Screen Shot 2019-07-31 at 10.03.48 PM.png

Introduction to Importing Data in R

XLConnect

  • Martin Studer

  • Work with Excel through R

  • Bridge between Excel and R

  • XLS and XLSX

  • Easy-to-use functionality

Introduction to Importing Data in R

Installation

install.packages("XLConnect")
also installing the dependencies 'XLConnectJars', 'rJava'
...
  • Problems?
    • Install Oracle's Java Development Kit (JDK)
    • Google your error!
Introduction to Importing Data in R

loadWorkbook()

library("XLConnect")

book <- loadWorkbook("cities.xlsx")
str(book)
Formal class 'workbook' [package "XLConnect"] with 2 slots
  ..@ filename: chr "cities.xlsx"
  ..@ jobj    : ...
Introduction to Importing Data in R

getSheets()

getSheets(book)

"year_1990" "year_2000"

library(readxl)
excel_sheets("cities.xlsx")
"year_1990" "year_2000"
Introduction to Importing Data in R

readWorksheet()

readWorksheet(book, sheet = "year_2000")

    Capital Population
1  New York   17800000
2    Berlin    3382169
3    Madrid    2938723
4 Stockholm    1942362
Introduction to Importing Data in R

readWorksheet()

Screen Shot 2019-07-31 at 10.13.15 PM.png

readWorksheet(book, sheet = "year_2000",                 
              startRow = 3, 
              endRow = 4,                 
              startCol = 2, 
              header = FALSE)

     Col1
1 3382169
2 2938723
Introduction to Importing Data in R

Let's practice!

Introduction to Importing Data in R

Preparing Video For Download...