library(dplyr)
raw <- "2017-2019-pr2-2-Person.csv"
RawPath <- here::here(paste0("data-raw/", raw))
PSRCZipPath <- here::here("data-raw/2017-2019-pr2-datafiles.zip")
PSRCDataURL <- "https://www.psrc.org/sites/default/files/2017-2019-pr2-datafiles.zip"
if(!file.exists(RawPath)) {
if(!file.exists(PSRCZipPath)) {
download.file(PSRCDataURL, PSRCZipPath)
}
unzip(PSRCZipPath, files = raw, exdir = here::here("data-raw/"))
}
raw_pr <- readr::read_csv(RawPath,
guess_max = 7000) #`guess_max` increases max # rows looked at to determine col type
prdat <- raw_pr %>%
rename(personid = person_id) %>%
mutate(across(c(personid, hhid), ~ as.character(.x)),
age = ordered(age,
c("Under 5 years old",
"5-11 years",
"12-15 years",
"16-17 years",
"18-24 years",
"25-34 years",
"35-44 years",
"45-54 years",
"55-64 years",
"65-74 years",
"75-84 years",
"85 or years older")),
age_category = ordered(age_category,
c("Under 18 years",
"18-64 years",
"65 years+")),
gender = factor(gender,
c("Male",
"Female",
"Another",
"Prefer not to answer")),
relationship = factor(relationship,
c("Self",
"Spouse or partner",
"Son or daughter (or child in-law)",
"Father or mother (or parent in-law)",
"Brother or sister (or sibling in-law)",
"Other relative",
"Roommate/Friend",
"Household help",
"Other")),
employment = ordered(employment,
c("Employed full time (35+ hours/week, paid)",
"Employed part time (fewer than 35 hours/week, paid)",
"Self-employed",
"Unpaid volunteer or intern",
"Homemaker",
"Retired",
"Not currently employed")),
jobs_count = ordered(jobs_count,
c("0 jobs",
"1 job",
"2 jobs",
"3 jobs",
"4 jobs",
"5 or more jobs")),
education = ordered(education,
c("Less than high school",
"High school graduate",
"Some college",
"Vocational/technical training",
"Associates degree",
"Bachelor degree",
"Graduate/post-graduate degree")),
student = ordered(student,
c("No, not a student",
"Part-time student",
"Full-time student")),
schooltype = ordered(schooltype,
c("Daycare",
"Preschool",
"K-12 public school",
"K-12 private school",
"K-12 home school (full-time or part-time)",
"College, graduate, or professional school",
"Vocational/technical school",
"Other",
"None")),
workplace = ordered(workplace,
c("Usually the same location (outside home)",
"Workplace regularly varies (different offices or jobsites)",
"At home (telecommute or self-employed with home office)",
"Drives for a living (e.g., bus driver, salesperson)")),
license = ordered(license,
c("Yes, has an intermediate or unrestricted license",
"Yes, has a learner’s permit",
"No, does not have a license or permit")),
commute_freq = ordered(commute_freq,
c("Less than monthly",
"A few times per month",
"1 day a week",
"2 days a week",
"3 days a week",
"4 days a week",
"5 days a week",
"6-7 days a week")),
commute_mode = ordered(commute_mode,
c("Drive alone",
"Carpool ONLY with other household members",
"Carpool with other people not in household (may also include household members)",
"Motorcycle/moped/scooter",
"Vanpool",
"Bicycle or e-bike",
"Walk, jog, or wheelchair",
"Bus (public transit)",
"Private bus or shuttle",
"Paratransit",
"Commuter rail (Sounder, Amtrak)",
"Urban rail (Link light rail, monorail)",
"Streetcar",
"Ferry or water taxi",
"Taxi (e.g., Yellow Cab)",
"Other hired service (Uber, Lyft, or other smartphone-app car service)",
"Airplane or helicopter",
"Scooter or e-scooter (e.g., Lime, Bird, Razor)",
"Motorcycle/moped",
"Other (e.g. skateboard)")),
telecommute_freq = ordered(telecommute_freq,
c("Not applicable",
"Never",
"Less than monthly",
"A few times per month",
"1 day a week",
"2 days a week",
"3 days a week",
"4 days a week",
"5 days a week",
"6-7 days a week")),
across(starts_with("mode_freq_"),
~ ordered(.x,
c("I never do this",
"I do this, but not in the past 30 days",
"1-3 times in the past 30 days",
"1 day/week",
"2-4 days/week",
"5 days/week",
"6-7 days/week"))),
across(starts_with("wbt_transit"),
~ if_else(mode_freq_1 >= "5 days/week", "Already use 5+ days/week", .x)),
across(starts_with("wbt_bike"),
~ if_else(mode_freq_2 >= "5 days/week", "Already use 5+ days/week", .x)),
across(starts_with("wbt_"),
~ ordered(.x,
c("Not Applicable",
"Never",
"Rarely (1-3 times per month)",
"Occasionally (1-2 days per week)",
"Somewhat often (3-5 days per week)",
"Regularly (6-7 days per week)",
"Already use 5+ days/week"))),
across(starts_with("race") & !contains("race_category"),
~ factor(.x, c("Not Selected", "Selected"))),
race_category = factor(race_category,
c("White Only",
"Child",
"Other",
"Asian",
"Missing",
"Hispanic",
"African American")),
worker = factor(worker,
c("No jobs",
"1+ job(s) (including part-time)"))
)
usethis::use_data(prdat, overwrite = TRUE, compress = "xz")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.