a case
df=data.frame(id=c(101,102,102,103,104,104,104), calmonth=c(\'01\',\'01\',\'01\',\'01\',\'01\',\'01\',\'02\'), product=c(\'
If you prefer SQL syntax then use sqldf package:
sqldf
library(sqldf) sqldf(" select * from ( select id, calmonth, group_concat(product, ' & ') product from df group by id, calmonth ) where product='apple & htc' and calmonth='01' ")