Closed wfmackey closed 3 years ago
something like
.data %>% separate(income, into = c("drop", "low_income", "high_income"), sep = "\\$") %>% mutate(across(c(low_income, high_income), ~parse_number(.) * 52), low_income = if_else(low_income == 52, 0, low_income), high_income = if_else(low_income == 156000, 156000, high_income + 51), mid_income = (low_income + high_income) / 2) %>% select(-drop) %>% replace_na(list(low_income = 0, high_income = 0, mid_income = 0))
which adds three variables (low_, mid_ and high_income). Or maybe best to keep it as a function which returns a vector so can be used inside a mutate call, eg
low_
mid_
high_income
mutate
data %>% mutate(low_income = parse_income(income, return = "lower_limit"), high_income = parse_income(income, return = "upper_limit"))
you better believe I stuck an 👀 emoji on this
something like
which adds three variables (
low_
,mid_
andhigh_income
). Or maybe best to keep it as a function which returns a vector so can be used inside amutate
call, eg