Created
August 2, 2018 10:28
-
-
Save jaehyeon-kim/3c7c45d056cd427cfea5eab35f690ecd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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