+ - 0:00:00
Notes for current slide
Notes for next slide

Data basics

1 / 18

Packages

2 / 18
R packages, base
3 / 18
R packages, other
4 / 18

Using packages

install.packages("name")

Downloads files
to your computer

Do this once per computer

5 / 18

Using packages

install.packages("name")

Downloads files
to your computer

Do this once per computer

library("name")

Loads the package

Do this once per R session

5 / 18

The tidyverse

"The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures."

… the tidyverse makes data science faster, easier and more fun…

The tidyverse
6 / 18

The tidyverse

tidyverse and language
7 / 18

From "Master the Tidyverse" by RStudio

The tidyverse package

library(tidyverse)

The tidyverse package is a shortcut for
installing and loading all the key tidyverse packages

8 / 18
install.packages("tidyverse")
install.packages("ggplot2")
install.packages("dplyr")
install.packages("tidyr")
install.packages("readr")
install.packages("purrr")
install.packages("tibble")
install.packages("stringr")
install.packages("forcats")
install.packages("lubridate")
install.packages("hms")
install.packages("DBI")
install.packages("haven")
install.packages("httr")
install.packages("jsonlite")
install.packages("readxl")
install.packages("rvest")
install.packages("xml2")
install.packages("modelr")
install.packages("broom")
9 / 18
install.packages("tidyverse")
install.packages("ggplot2")
install.packages("dplyr")
install.packages("tidyr")
install.packages("readr")
install.packages("purrr")
install.packages("tibble")
install.packages("stringr")
install.packages("forcats")
install.packages("lubridate")
install.packages("hms")
install.packages("DBI")
install.packages("haven")
install.packages("httr")
install.packages("jsonlite")
install.packages("readxl")
install.packages("rvest")
install.packages("xml2")
install.packages("modelr")
install.packages("broom")
library("tidyverse")
library("ggplot2")
library("dplyr")
library("tidyr")
library("readr")
library("purrr")
library("tibble")
library("stringr")
library("forcats")
9 / 18

Rectangular data

10 / 18

Data frames and tibbles

Data frames are the most common kind of data objects; used for rectangular data (like spreadsheets)

11 / 18

Data frames and tibbles

Data frames are the most common kind of data objects; used for rectangular data (like spreadsheets)

Data frames: R's native data object

11 / 18

Data frames and tibbles

Data frames are the most common kind of data objects; used for rectangular data (like spreadsheets)

Data frames: R's native data object

Tibbles (tbl): a fancier enhanced kind of data frame

11 / 18

Data frames and tibbles

Data frames are the most common kind of data objects; used for rectangular data (like spreadsheets)

Data frames: R's native data object

Tibbles (tbl): a fancier enhanced kind of data frame

(You really won't notice a difference today)

11 / 18

Vectors and lists

12 / 18

Vectors

Vectors are a list of values of the same time
(all text, or all numbers, etc.)

Make them with c():

c(1, 4, 2, 5, 7)
13 / 18

Vectors

Vectors are a list of values of the same time
(all text, or all numbers, etc.)

Make them with c():

c(1, 4, 2, 5, 7)

You'll usually want to assign them to something:

neat_numbers <- c(1, 4, 2, 5, 7)
13 / 18

Basic data types

Integer Whole numbers c(1, 2, 3, 4)
Double Numbers c(1, 2.4, 3.14, 4)
Character Text c("1", "blue", "fun", "monster")
Logical True or false c(TRUE, FALSE, TRUE, FALSE)
Factor Category c("Strongly disagree", "Agree", "Neutral")
14 / 18

Importing data

15 / 18

Packages for importing data

readr Work with plain text data my_data <- read_csv("file.csv")
readxl Work with Excel files my_data <- read_excel("file.xlsx")
haven Work with Stata, SPSS, and SAS data my_data <- read_stata("file.dta")
16 / 18

Other types of data

Package Type of data
jsonlite JSON data
xml2 XML data
httr Web APIs
rvest Web pages (web scraping)
DBI Databases (SQL)
17 / 18

Next up

Data visualization

18 / 18

Packages

2 / 18
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
oTile View: Overview of Slides
Esc Back to slideshow