Getting Set Up

Before we begin, start a new file with File \(\rightarrow\) New File \(\rightarrow\) R Script. As you work through this sheet in the console in R, also add (copy/paste) your commands that work into this new file. At the end, save it, and run to execute all of your commands at once.

First things first, load tidyverse.

library("tidyverse")
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.3     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.1     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.5.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()

Warm Up to dplyr With gapminder

1.

Load gapminder. select() the variables year, lifeExp, country.

library(gapminder)
# select(gapminder, c(year, lifeExp, country))

# using the pipe

gapminder %>%
  select(c(year, lifeExp, country))

2.

select() all variables except pop.

# select(gapminder, -pop)

# using the pipe

gapminder %>%
  select(-pop)