In this lab you can use the interactive console to explore or Knit the document. Remember anything you type here can be “sent” to the console with Cmd-Enter (OS-X) or Ctrl-Enter (Windows/Linux) in an R code chunk.
Read in the SARS-CoV-2 wastewater data from URL https://daseh.org/data/SARS-CoV-2_Wastewater_Data.csv
and assign it to an object named covid
.
# General format
library(readr)
# OBJECT <- read_csv(FILE)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
covid <- read_csv(file = "https://daseh.org/data/SARS-CoV-2_Wastewater_Data.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 776059 Columns: 12
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): reporting_jurisdiction, sample_location, key_plot_id, county_names...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Filter the dataset so that the “reporting_jurisdiction” column is
equal to “Maryland”. Store the modified dataset as
covid_filtered
.
# General format
NEW_OBJECT <- OBJECT %>% filter(COLUMNNAME == CRITERIA)
covid_filtered <- covid %>% filter(reporting_jurisdiction == "Maryland")
Write out the covid_filtered
object as a CSV file
calling it “covid_filtered.csv”, using write_csv()
:
write_csv(covid_filtered, file = "covid_filtered.csv")
Copy your code from problem 1.3 and modify it to write to the data directory inside your R Project. Note: you may need to make a new folder named “data” if it doesn’t already exist.
getwd()
dir.create("data")
write_csv(covid_filtered, file = "data/covid_filtered.csv")
Write one of the objects in your Environment to your working
directory in rds
format. Call the file
my_variable.rds
.
y <- c(10, 20, 30, 40, 50, 60)
write_rds(y, file = "my_variable.rds")
Read the RDS file from your working directory back into your
Environment. Call the file z
.
z <- read_rds(file = "my_variable.rds")