Skip to content

Instantly share code, notes, and snippets.

@MilesMcBain
Created February 22, 2017 14:00
Show Gist options
  • Save MilesMcBain/8febe19be00a45036d9666976ceb6276 to your computer and use it in GitHub Desktop.
Save MilesMcBain/8febe19be00a45036d9666976ceb6276 to your computer and use it in GitHub Desktop.
dat <- readr::read_csv("municipality\n- Ticino\n>> Distretto di Bellinzona\n......5001 Arbedo-Castione\n......5002 Bellinzona\n......5003 Cadenazzo\n......5004 Camorino\n")
dat %>% mutate(municipality = gsub(pattern = '[\\.\\>]|^-',
replacement = "",
municipality)) %>%
separate(col = municipality,
sep = '(?<=[0-9])\\s',
into = c ("code","municipality"),
fill = "left")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment