I have the following data:
request user group 1 1 1 4 1 1 7 1 1 5 1 2 8 1 2 1 2
aggregate gets you very close:
aggregate
dat <- data.frame( user = c(1,1,1,2,2,3,3,3,4), group = c(1,1,1,1,1,2,2,2,2), request = c(1,4,7,5,8,1,4,7,9) ) aggregate(request~group + user, dat, FUN=c) group user request 1 1 1 1, 4, 7 2 1 2 5, 8 3 2 3 1, 4, 7 4 2 4 9