readxl (1)

Introduktion till dataimport i R

Filip Schouwenaars

Instructor, DataCamp

Microsoft Excel

  • Vanligt verktyg för dataanalys
  • Många R-paket för att arbeta med Excel
  • readxl – Hadley Wickham
Introduktion till dataimport i R

Typisk struktur för Excel-data

  • Olika flikar med tabelldata

Skärmdump 2019-07-15 kl. 15.27.34.png

Introduktion till dataimport i R

readxl

  • excel_sheets()
    • listar olika flikar
  • read_excel()
    • importerar data till R
install.packages("readxl")
library(readxl)
Introduktion till dataimport i R

excel_sheets()

dir()
"cities.xlsx"  "the_rest_is_secret.txt"
excel_sheets("cities.xlsx")
"year_1990" "year_2000"
Introduktion till dataimport i R

read_excel()

read_excel("cities.xlsx")
# A tibble: 4 × 2
    Capital Population
      <chr>      <dbl>
1  New York   16044000
2    Berlin    3433695
3    Madrid    3010492
4 Stockholm    1683713
read_excel("cities.xlsx", sheet = 2)
read_excel("cities.xlsx", sheet = "year_2000")
# A tibble: 4 × 2
    Capital Population
      <chr>      <dbl>
1  New York   17800000
2    Berlin    3382169
3    Madrid    2938723
4 Stockholm    1942362
Introduktion till dataimport i R

Nu kör vi en övning!

Introduktion till dataimport i R

Preparing Video For Download...