Code
<- read.csv("https://raw.githubusercontent.com/melaniewalsh/Neat-Datasets/main/1979-2020-National-Park-Visits-By-State.csv",
np_data stringsAsFactors = FALSE)
February 26, 2024
View the np_data dataframe by clicking on the spreadsheet icon in the Global Environment
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!
How does the number of visits to Washington national parks compare to another state?
Filter the dataframe for only values in the state of Washington and save to the variable wa_parks
Calculate the sum total of RecreationVisits to Washington by using summarize() on the smaller dataframe wa_parks
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().
How do the number of visits to these 2 states compare to one another?
---
title: "Introduction to DPLYR with National Park Visitation Data (Exercise)"
date: "2024-02-26"
categories: [dplyr, exercise, solution]
format:
html:
code-links:
- text: R Script
href: Intro-to-DPLYR-NP.R
icon: file-code
#image: "https://upload.wikimedia.org/wikipedia/commons/e/ed/US-Mexico_barrier_map.png"
code-overflow: wrap
code-fold: show
editor: visual
df-print: kable
R.options:
warn: false
code-tools: true
execute:
eval: false
---
# <span style="color:green;"> Exercises </span>
## Introduction to DPLYR with National Park Visitation Data
<a href="Intro-to-DPLYR-NP.R" download="Intro-to-DPLYR-NP.R">Download as R Script</a>
<span style="color:red;"> [Solutions](Intro-to-DPLYR-NP-Solutions.qmd) </span>
# Load National Park Visitation data
```{r}
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
```{r}
install.packages("tidyverse")
```
# Load dplyr library
```{r}
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!
```{r}
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
```{r}
Your code here
```
# Exercise 3
Calculate the sum total of RecreationVisits to Washington by using summarize() on the smaller dataframe wa_parks
```{r}
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().
```{r}
Your code here
```
How do the number of visits to these 2 states compare to one another?