Skip to content

Instantly share code, notes, and snippets.

@edgararuiz-zz
Created August 2, 2018 03:18
Show Gist options
  • Save edgararuiz-zz/13ac5067c0e914e1013cc725a89975bc to your computer and use it in GitHub Desktop.
Save edgararuiz-zz/13ac5067c0e914e1013cc725a89975bc to your computer and use it in GitHub Desktop.
library(tidyverse, warn.conflicts = FALSE)
df <- tribble(
~id, ~port,
"a", "22,33",
"a", "22,44",
"b", "33, 434"
)
df %>%
transpose() %>%
map_df(~tibble(
id = .x$id,
port = str_split(.x$port, ",")[[1]])
) %>%
group_by(id) %>%
filter(!duplicated(port)) %>%
summarise(port = paste0(port, collapse = ","))
#> # A tibble: 2 x 2
#> id port
#> <chr> <chr>
#> 1 a 22,33,44
#> 2 b 33, 434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment