Merges two data frames based on specified columns. By default merges only matching rows.
df <- merge(purchases, hists, by.x = c('user', 'year', 'month'), by.y = c('representative_id', 'year', 'month'))