Skip to content

Instantly share code, notes, and snippets.

@jaehyeon-kim
Created August 2, 2018 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaehyeon-kim/3c7c45d056cd427cfea5eab35f690ecd to your computer and use it in GitHub Desktop.
Save jaehyeon-kim/3c7c45d056cd427cfea5eab35f690ecd to your computer and use it in GitHub Desktop.
library(magrittr)
library(dplyr)
sep <- function(s, delim=',') {
strsplit(s, delim) %>%
unlist() %>%
unique() %>%
paste(collapse=',')
}
read.delim(header=TRUE, stringsAsFactors=FALSE,
text='
IP Port
A 22, 3389
A 8080, 22
A 6060, 3389
B 443, 666, 1080
B 50000, 443
C 3389, 3003
C 22, 4000
C 3389
') %>%
mutate(Port=gsub(' ', '', Port)) %>%
group_by(IP) %>%
summarise(Port=sep(paste(Port, collapse=','))) %>%
ungroup()
# A tibble: 3 x 2
IP Port
<chr> <chr>
1 A 22,3389,8080,6060
2 B 443,666,1080,50000
3 C 3389,3003,22,4000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment