fhdsl / DaSEH

🌼 Collection of materials to accompany the R25 funded "Data Science for Environmental Health" short course
https://daseh.org
MIT License
0 stars 1 forks source link

cleaning lecture improvement #216

Open carriewright11 opened 1 month ago

carriewright11 commented 1 month ago
carriewright11 commented 1 month ago

library(tidyverse)

ces <- read_csv(file = "https://daseh.org/data/CalEnviroScreen_data.csv")

more complicated case_when example with 2 columns:

ces %>% mutate(new_col_case_when = case_when(Longitude < -121 & Latitude > 37.8 ~ "Distract A", TRUE ~ "District B")) %>% pull(new_col_case_when)

don't need case_when if just doing a calcuation with other variables:

ces %>% mutate(num_col_mutate = Longitude * Latitude ) %>% pull(num_col_mutate)

more complicated example - will get NA values (on purpose - no TRUE statement) of calculation for cases where the condition is not met:

ces %>% mutate(num_new = case_when(Longitude < -121 & Latitude > 37.8 ~ Longitude * Latitude)) %>% pull(num_new)

carriewright11 commented 1 month ago

could also add an extra slide about n_complete_row