Chapter 3
Chapter 3
I N T R O D U C T I O N T O I M P O R T I N G D ATA I N R
Filip Schouwenaars
Instructor, DataCamp
Microsoft Excel
Common data analysis tool
Many R packages to interact with Excel
read_excel()
actually import data into R
install.packages("readxl")
library(readxl)
"cities.xlsx" "the_rest_is_secret.txt"
excel_sheets("cities.xlsx")
"year_1990" "year_2000"
# 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
Filip Schouwenaars
Instructor, DataCamp
read_excel()
read_excel(path, sheet = 1,
col_names = TRUE,
col_types = NULL,
skip = 0)
# A tibble: 4 × 2
Capital Population
<chr> <chr>
1 New York 16044000
2 Berlin 3433695
3 Madrid 3010492
4 Stockholm 1683713
read_excel("cities.xlsx",
col_types = c("text", "blank"))
# A tibble: 4 × 1
Capital
<chr>
1 New York
2 Berlin
3 Madrid
4 Stockholm
read_excel("cities.xlsx",
col_names = c("Capital", "Population"),
skip = 2)
# A tibble: 3 × 2
Capital Population
<chr> <dbl>
1 Berlin 3433695
2 Madrid 3010492
3 Stockholm 1683713
Fast
Consistency