I have the following data frame:
╔══════╦═════════╗ ║ Code ║ Airline ║ ╠══════╬═════════╣ ║ 1 ║ AF ║ ║ 1 ║ KL ║ ║ 8 ║ AR ║ ║ 8 ║ A
You can try something like this in dplyr
dplyr
library(dplyr) df %>% group_by(code) %>% mutate(SharedWith = paste(sort(Airline), collapse = ', ')) %>% ungroup() %>% select(Airline, SharedWith)