Introduction to DPLYR with National Park Visitation Data (Exercise)

dplyr
exercise
solution
Published

February 26, 2024

Exercises

Introduction to DPLYR with National Park Visitation Data

Download as R Script

Solutions

Load National Park Visitation data

Code
np_data <- read.csv("https://raw.githubusercontent.com/melaniewalsh/Neat-Datasets/main/1979-2020-National-Park-Visits-By-State.csv",
 stringsAsFactors = FALSE)

View the np_data dataframe by clicking on the spreadsheet icon in the Global Environment

Install tidyverse

Code
install.packages("tidyverse")

Load dplyr library

Code
library(dplyr)

Exercise 1

Select 2 columns from the data using a DPLYR function. Save this 2-column dataframe to the variable smaller_df. Make sure to use the pipe %>% operator!

Code
smaller_df <- Your code here

How does the number of visits to Washington national parks compare to another state?

Exercise 2

Filter the dataframe for only values in the state of Washington and save to the variable wa_parks

Code
Your code here

Exercise 3

Calculate the sum total of RecreationVisits to Washington by using summarize() on the smaller dataframe wa_parks

Code
Your code here

Exercise 4

Filter the dataframe for only values in another state (your choice) and save to a variable. Calculate the sum total of RecreationVisits to this state by using summarize().

Code
Your code here

How do the number of visits to these 2 states compare to one another?