I have the following data frame:
╔══════╦═════════╗
║ Code ║ Airline ║
╠══════╬═════════╣
║ 1 ║ AF ║
║ 1 ║ KL ║
║ 8 ║ AR ║
║ 8 ║ A
split
helps. Here's a fully reproducible EDIT that works w/o any additional package. Works with the OPs data.frame - changed it after OP added a reproducible dataset.
# strip white space in Airline names:
dat$Airline <- gsub(" ","",dat$Airline)
li <- split(dat,factor(dat$Code))
do.call("rbind",lapply(li,function(x)
data.frame(Airline = x[1,2],
SharedWith = paste(x$Airline[-1]
,collapse=",")
))
)