Skip to content

Instantly share code, notes, and snippets.

@njtierney
Created March 15, 2018 05:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njtierney/3eabd1c77e24155e0b59c24b50b4c8da to your computer and use it in GitHub Desktop.
Save njtierney/3eabd1c77e24155e0b59c24b50b4c8da to your computer and use it in GitHub Desktop.

From Ben Fitzpatrick

ic_vec <- c('11% - 20%', '21% - 30%', '0% - 9%')

library(tidyverse)

ic_vec %>%
  as_tibble() %>%
  separate(col = value,
           into = c("lower", "upper"),
           sep = " - ") %>%
  mutate_if(.predicate = is.character,
            .funs = readr::parse_number)
#> # A tibble: 3 x 2
#>   lower upper
#>   <dbl> <dbl>
#> 1   11.   20.
#> 2   21.   30.
#> 3    0.    9.

Created on 2018-03-15 by the reprex package (v0.2.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment