I scraped several tables from a website to be used for a lookup table. I ended up with something similar to this:
a<-tibble(Group=c("A","B","B","B","C","C"),Code=c("2,3","15,16,18,","11,12,13,19,","14,13,15,18,110","111,","178,152,111"))
Now I'd like to convert this into a long tibble with two columns with unique key-value pairs in Group and d. I managed to do it, but my solution seems rather verbose. Is there another way of combining separate and gather to automate this?
a2<-a %>% separate(Code,sep = ',',into = paste0("n",c(1:5)),fill = "right",convert = T) %>%
gather(key=n,value = d,-Group) %>%
select(-n) %>%
filter(d!="" & !is.na(d)) %>%
distinct() %>%
arrange(Group,d)