read.delim & read.table

Introductie tot het importeren van data in R

Filip Schouwenaars

Instructor, DataCamp

Tab-gescheiden bestand

states.txt

state   capital pop_mill    area_sqm
South Dakota    Pierre  0.853   77116
New York    Albany  19.746  54555
Oregon  Salem  3.970   98381
Vermont Montpelier  0.627   9616
Hawaii  Honolulu    1.420   10931
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
Introductie tot het importeren van data in R

Exotisch bestandsformaat

states2.txt

state/capital/pop_mill/area_sqm
South Dakota/Pierre/0.853/77116
New York/Albany/19.746/54555
Oregon/Salem/3.970/98381
Vermont/Montpelier/0.627/9616
Hawaii/Honolulu/1.420/10931
Introductie tot het importeren van data in R

read.table()

  • Lees elk tabelbestand als een data frame

  • Heel veel argumenten beschikbaar

# Lees data met de eerste rij als kolomnamen
read.table("states2.txt", 
             header = TRUE, 
             sep = "/")
         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
Introductie tot het importeren van data in R

Laten we oefenen!

Introductie tot het importeren van data in R

Preparing Video For Download...