readr : read_csv et read_tsv

Introduction à l’importation de données dans R

Filip Schouwenaars

Instructor, DataCamp

Aperçu

  • Avant : package utils

  • Packages R dédiés

    • readr

    • data.table

Introduction à l’importation de données dans R

readr

  • Hadley Wickham

  • Rapide, simple, cohérent

  • utils : verbeux, plus lent

install.packages("readr")
library(readr)
Introduction à l’importation de données dans R

Fichiers CSV

read.csv("states.csv")
         state    capital pop_mill area_sqm
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
read_csv("states.csv")
# A tibble: 5 × 4
         state    capital pop_mill area_sqm
         <chr>      <chr>    <dbl>    <int>
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
Introduction à l’importation de données dans R

Fichiers TSV

read.delim("states.txt")
         state    capital pop_mill area_sqm
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
read_tsv("states.txt")
# A tibble: 5 × 4
         state    capital pop_mill area_sqm
         <chr>      <chr>    <dbl>    <int>
1 South Dakota     Pierre    0.853    77116
2     New York     Albany   19.746    54555
3       Oregon      Salem    3.970    98381
4      Vermont Montpelier    0.627     9616
5       Hawaii   Honolulu    1.420    10931
Introduction à l’importation de données dans R

Regrouper avec utils et readr

ch_2_1_slides.002.png

Introduction à l’importation de données dans R

Regrouper avec utils et readr

ch_2_1_slides.003.png

Introduction à l’importation de données dans R

Passons à la pratique !

Introduction à l’importation de données dans R

Preparing Video For Download...