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.
Load the tidyverse package. Then read in the CalEnviroScreen dataset from https://daseh.org/data/CalEnviroScreen_data.csv and assign it to an object named ces
.
# General format
library(tidyverse)
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
ces <- read_csv(file = "https://daseh.org/data/CalEnviroScreen_data.csv")
## Rows: 8035 Columns: 67
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): CaliforniaCounty, ApproxLocation, CES4.0PercRange
## dbl (64): CensusTract, ZIP, Longitude, Latitude, CES4.0Score, CES4.0Percenti...
##
## ℹ 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 CaliforniaCounty
column is equal to “Yuba”. Store the modified dataset as ces_Yuba
.
# General format
NEW_OBJECT <- OBJECT %>% filter(COLUMNNAME == CRITERIA)
ces_Yuba <- ces %>% filter(CaliforniaCounty == "Yuba")
Write out the ces_Yuba
object as a CSV file calling it “ces_Yuba.csv”, using write_csv()
:
write_csv(ces_Yuba, file = "ces_Yuba.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() # Check -- are you in the project directory?
write_csv(ces_Yuba, file = "data/ces_Yuba.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 you just created from your working directory back into your Environment. Call the file z
.
z <- read_rds(file = "my_variable.rds")