0% found this document useful (0 votes)
13 views15 pages

Chapter 3

capitulo 3 sobre introducción al r

Uploaded by

zopauy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

Chapter 3

capitulo 3 sobre introducción al r

Uploaded by

zopauy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

readxl (1)

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

readxl - Hadley Wickham

INTRODUCTION TO IMPORTING DATA IN R


Typical Structure Excel Data
Different sheets with tabular data

INTRODUCTION TO IMPORTING DATA IN R


readxl
excel_sheets()
list different sheets

read_excel()
actually import data into R

install.packages("readxl")
library(readxl)

INTRODUCTION TO IMPORTING DATA IN R


excel_sheets()
dir()

"cities.xlsx" "the_rest_is_secret.txt"

excel_sheets("cities.xlsx")

"year_1990" "year_2000"

INTRODUCTION TO IMPORTING DATA IN 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

INTRODUCTION TO IMPORTING DATA IN R


Let's practice!
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
readxl (2)
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
read_excel()
read_excel(path, sheet = 1,
col_names = TRUE,
col_types = NULL,
skip = 0)

INTRODUCTION TO IMPORTING DATA IN R


read_excel() - col_names
read_excel(path, sheet = 1,
col_names = TRUE,
col_types = NULL,
skip = 0)

col_names = FALSE: R assigns names itself

col_names = character vector: manually specify

INTRODUCTION TO IMPORTING DATA IN R


read_excel() - col_types
read_excel(path, sheet = 1,
col_names = TRUE,
col_types = NULL,
skip = 0)

read_excel("cities.xlsx", col_types = c("text", "text"))

# A tibble: 4 × 2
Capital Population
<chr> <chr>
1 New York 16044000
2 Berlin 3433695
3 Madrid 3010492
4 Stockholm 1683713

INTRODUCTION TO IMPORTING DATA IN R


read_excel() - col_types
read_excel(path, sheet = 1,
col_names = TRUE,
col_types = NULL,
skip = 0)`

read_excel("cities.xlsx",
col_types = c("text", "blank"))

# A tibble: 4 × 1
Capital
<chr>
1 New York
2 Berlin
3 Madrid
4 Stockholm

INTRODUCTION TO IMPORTING DATA IN R


read_excel() - skip
read_excel(path, sheet = 1,
col_names = TRUE,
col_types = NULL,
skip = 0)

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

INTRODUCTION TO IMPORTING DATA IN R


Wrap-up
excel_sheets()
read_excel()

Everything you need!

Fast

Same arguments as in readr package

Consistency

INTRODUCTION TO IMPORTING DATA IN R


Let's practice!
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

You might also like