Läsa kalkylblad

Introduktion till dataimport i R

Filip Schouwenaars

Instructor, DataCamp

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

Introduktion till dataimport i R

XLConnect

  • Martin Studer

  • Arbeta med Excel via R

  • Brygga mellan Excel och R

  • XLS och XLSX

  • Lättanvänd funktionalitet

Introduktion till dataimport i R

Installation

install.packages("XLConnect")
also installing the dependencies 'XLConnectJars', 'rJava'
...
  • Problem?
    • Installera Oracles Java Development Kit (JDK)
    • Googla felmeddelandet!
Introduktion till dataimport i R

loadWorkbook()

library("XLConnect")

book <- loadWorkbook("cities.xlsx")
str(book)
Formal class 'workbook' [package "XLConnect"] with 2 slots
  ..@ filename: chr "cities.xlsx"
  ..@ jobj    : ...
Introduktion till dataimport i R

getSheets()

getSheets(book)

"year_1990" "year_2000"

library(readxl)
excel_sheets("cities.xlsx")
"year_1990" "year_2000"
Introduktion till dataimport i R

readWorksheet()

readWorksheet(book, sheet = "year_2000")

    Capital Population
1  New York   17800000
2    Berlin    3382169
3    Madrid    2938723
4 Stockholm    1942362
Introduktion till dataimport i 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
Introduktion till dataimport i R

Nu kör vi en övning!

Introduktion till dataimport i R

Preparing Video For Download...