The aggregate function should help you find a solution:
dat = data.frame(title = c("title1", "title2", "title3"), author = c("author1", "author2", "author3"), customerID = c(1, 2, 1)) aggregate(dat[-3], by=list(dat$customerID), c) # Group.1 title author # 1 1 1, 3 1, 3 # 2 2 2 2
Or just make sure you add stringsAsFactors = FALSE when you create your data frame and you are very good. If your data has already been accounted for, you can use something like dat[c(1, 2)] = apply(dat[-3], 2, as.character) to convert them to a character first, and then:
aggregate(dat[-3], by=list(dat$customerID), c)
A5C1D2H2I1M1N2O1R2T1
source share