From 623004c2ac11b57872a8d94df37a1b12cea1709c Mon Sep 17 00:00:00 2001 From: jensenmj Date: Fri, 8 Nov 2024 16:49:21 -0800 Subject: [PATCH] Fix frequency grouping functions to use the proper variables & labels. --- R/psrc-hts-recode-person-vars.R | 18 +++++++++--------- man/hts_bin_bike_frequency.Rd | 22 ++++++++++++++++++++++ man/hts_bin_transit_frequency.Rd | 22 ++++++++++++++++++++++ man/hts_bin_walk_frequency.Rd | 22 ++++++++++++++++++++++ 4 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 man/hts_bin_bike_frequency.Rd create mode 100644 man/hts_bin_transit_frequency.Rd create mode 100644 man/hts_bin_walk_frequency.Rd diff --git a/R/psrc-hts-recode-person-vars.R b/R/psrc-hts-recode-person-vars.R index 7038502..da1c81f 100644 --- a/R/psrc-hts-recode-person-vars.R +++ b/R/psrc-hts-recode-person-vars.R @@ -346,9 +346,9 @@ hts_bin_transit_frequency <- function(hts_data){ }else{ hts_data$person %<>% setDT() %>% .[, transit_frequency_bin4:=factor( - fcase(safegsub("(\\d-)?(\\d) days? a week$", as.character(telecommute_freq)) %between% c(1,4), "1-4 days a week", - safegsub("(\\d-)?(\\d) days a week$", as.character(telecommute_freq)) %between% c(5,7), "5-7 days a week", - !is.na(telecommute_freq), as.character(telecommute_freq)), + fcase(safegsub("\\d?-?(\\d) days? a week$", as.character(transit_frequency)) %between% c(1,4), "1-4 days a week", + safegsub("\\d?-?(\\d) days a week$", as.character(transit_frequency)) %between% c(5,7), "5-7 days a week", + !is.na(transit_frequency), as.character(transit_frequency)), levels=c("1-4 days a week", "5-7 days a week", "1-3 days in the past month", "Never in the past 30 days"))] labelled::var_label(hts_data$person$transit_frequency_bin4) <- "Frequency of transit use" } @@ -369,9 +369,9 @@ hts_bin_walk_frequency <- function(hts_data){ }else{ hts_data$person %<>% setDT() %>% .[, walk_frequency_bin4:=factor( - fcase(safegsub("(\\d-)?(\\d) days? a week$", as.character(telecommute_freq)) %between% c(1,4), "1-4 days a week", - safegsub("(\\d-)?(\\d) days a week$", as.character(telecommute_freq)) %between% c(5,7), "5-7 days a week", - !is.na(telecommute_freq), as.character(telecommute_freq)), + fcase(safegsub("\\d?-?(\\d) days? a week$", as.character(walk_frequency)) %between% c(1,4), "1-4 days a week", + safegsub("\\d?-?(\\d) days a week$", as.character(walk_frequency)) %between% c(5,7), "5-7 days a week", + !is.na(walk_frequency), as.character(walk_frequency)), levels=c("1-4 days a week", "5-7 days a week", "1-3 days in the past month", "Never in the past 30 days"))] labelled::var_label(hts_data$person$walk_frequency_bin4) <- "Frequency of walk use" } @@ -392,9 +392,9 @@ hts_bin_bike_frequency <- function(hts_data){ }else{ hts_data$person %<>% setDT() %>% .[, bike_frequency_bin4:=factor( - fcase(safegsub("(\\d-)?(\\d) days? a week$", as.character(telecommute_freq)) %between% c(1,4), "1-4 days a week", - safegsub("(\\d-)?(\\d) days a week$", as.character(telecommute_freq)) %between% c(5,7), "5-7 days a week", - !is.na(telecommute_freq), as.character(telecommute_freq)), + fcase(safegsub("\\d?-?(\\d) days? a week$", as.character(bike_frequency)) %between% c(1,4), "1-4 days a week", + safegsub("\\d?-?(\\d) days a week$", as.character(bike_frequency)) %between% c(5,7), "5-7 days a week", + !is.na(bike_frequency), as.character(bike_frequency)), levels=c("1-4 days a week", "5-7 days a week", "1-3 days in the past month", "Never in the past 30 days"))] labelled::var_label(hts_data$person$bike_frequency_bin4) <- "Frequency of bike use" } diff --git a/man/hts_bin_bike_frequency.Rd b/man/hts_bin_bike_frequency.Rd new file mode 100644 index 0000000..b8a4f7e --- /dev/null +++ b/man/hts_bin_bike_frequency.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/psrc-hts-recode-person-vars.R +\name{hts_bin_bike_frequency} +\alias{hts_bin_bike_frequency} +\title{Add generalized bike frequency +Requires `bike_frequency` variable} +\usage{ +hts_bin_bike_frequency(hts_data) +} +\arguments{ +\item{hts_data}{the hts_data list object} +} +\value{ +hts_data with a generalized bike frequency variable +} +\description{ +Add generalized bike frequency +Requires `bike_frequency` variable +} +\author{ +Michael Jensen +} diff --git a/man/hts_bin_transit_frequency.Rd b/man/hts_bin_transit_frequency.Rd new file mode 100644 index 0000000..f621b95 --- /dev/null +++ b/man/hts_bin_transit_frequency.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/psrc-hts-recode-person-vars.R +\name{hts_bin_transit_frequency} +\alias{hts_bin_transit_frequency} +\title{Add generalized transit frequency +Requires `transit_frequency` variable} +\usage{ +hts_bin_transit_frequency(hts_data) +} +\arguments{ +\item{hts_data}{the hts_data list object} +} +\value{ +hts_data with a generalized transit frequency variable +} +\description{ +Add generalized transit frequency +Requires `transit_frequency` variable +} +\author{ +Michael Jensen +} diff --git a/man/hts_bin_walk_frequency.Rd b/man/hts_bin_walk_frequency.Rd new file mode 100644 index 0000000..724f1b2 --- /dev/null +++ b/man/hts_bin_walk_frequency.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/psrc-hts-recode-person-vars.R +\name{hts_bin_walk_frequency} +\alias{hts_bin_walk_frequency} +\title{Add generalized walk frequency +Requires `walk_frequency` variable} +\usage{ +hts_bin_walk_frequency(hts_data) +} +\arguments{ +\item{hts_data}{the hts_data list object} +} +\value{ +hts_data with a generalized walk frequency variable +} +\description{ +Add generalized walk frequency +Requires `walk_frequency` variable +} +\author{ +Michael Jensen +}