Skip to content

Instantly share code, notes, and snippets.

@JosiahParry
Created November 10, 2022 21:39
Show Gist options
  • Save JosiahParry/8d28947999783aef4cde3f1b25f86515 to your computer and use it in GitHub Desktop.
Save JosiahParry/8d28947999783aef4cde3f1b25f86515 to your computer and use it in GitHub Desktop.
tidy up route names
make_route_name <- function(x) {
strsplit(x, ", ") |>
unlist() |>
unique() |>
paste(collapse = ", ")
}
routes <- c("426, 442, 450, 455, T116", "113, 99, T109, T110")
make_route_name(routes)
#> [1] "426, 442, 450, 455, T116, 113, 99, T109, T110"
@JosiahParry
Copy link
Author

Use this funciton within your dplyr mutate call.

Something like

df |> 
  group_by(col, col2) |>
  summarise(route_name = make_route_name(route_col))

@aseemdeodhar
Copy link

worked beautifully - thank you!

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