Docsity

Data Wrangling and Scraping using R: A Comprehensive Guide, Slides of Logic

Partial preview of the text

Download Data Wrangling and Scraping using R: A Comprehensive Guide and more Slides Logic in PDF only on Docsity!

Intro to Data Wrangling &

Scraping Using R

Mochamad Kautzar Ichramsyah Senior Data Analyst - Traveloka ICW-HDDA-X 2020

About Data Wrangling

About Data Wrangling (2)

https://www.nytimes.com/2014/08/18/technology/for-big-data-scientists-hurdle-to-insights-is-janitor-work.html

Data Wrangling Using R

Data Wrangling Using R (2)

Two packages to help us

doing magic with the structure of data.

tidyr

dplyr

install.packages(c('tidyr', 'dplyr'))

library(tidyr)

library(dplyr)

Data Wrangling Using R (3)

Another packages we may need.

devtools

EDAWR

install.packages('devtools') library(devtools) install_github('rstudio/EDAWR') library(EDAWR)

?storms ?cases ?pollution ?tb

Data Wrangling Using R (5)

  • 1007 / storms$pressure / storms$wind
    • 1009 /
    • 1005 /
    • 1013 /
    • 1010 /
    • 1010 /

Tidying Data Using tidyr

Tidying Data Using tidyr (2)

Tidy Data!

Easy to access

Preserves observations

Tidying Data Using tidyr (3)

tidyr

Package to reshape layout of tables.

Two main functions:

gather()

spread()

# install.packages('tidyr')

library('tidyr')

?gather

?spread

Tidying Data Using tidyr (5)

gather()

key = 'year' (former column names) value = 'count' (former cells)

Tidying Data Using tidyr (6)

gather(cases, 'year', 'count', 2:4)

Function to reshape the data frame.

Collapses multiple columns into two columns.

Name of the new key column. String.

Name of the new value column. String.

Names or numeric indexes of columns to collapse.

Data frame to reshape.

Tidying Data Using tidyr (8)

spread()

key = size (former column1 names) value = amount (former column2 names)

Tidying Data Using tidyr (9)

spread(pollution, size, amount)

Function to reshape the data frame.

Generates multiple columns from two columns.

Column to use for keys, create new column names.

Column to use for values, create new column cells.

Data frame to reshape.