runapp-aus / strayr

A catalogue of ready-to-use ABS coding structures. Package documentation can be found here: https://runapp-aus.github.io/strayr/
45 stars 15 forks source link

Add functions for parsing income buckets #18

Closed wfmackey closed 3 years ago

wfmackey commented 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

data %>%
  mutate(low_income = parse_income(income, return = "lower_limit"),
               high_income = parse_income(income, return = "upper_limit"))
MattCowgill commented 3 years ago

you better believe I stuck an 👀 emoji on this