Merge problems in R: Error in fix.by(by.x, x) : ‘by’ must specify uniquely valid columns

I have two tables, both of which are aggregate outputs. I’d like to merge them together – they were both aggregated off the same data, so they have the same column names, but for the sake of edification I thought I’d try the specific by.x and by.y methods in the examples of ?merge.

merge(medA,countA, 
      by = c("manager_id", "manager_name", "grouping"))
## this works

merge(medA,countA, 
  by.x = c(medA$manager_id, medA$manager_name, medA$grouping), 
  by.y = c(countA$manager_id, countA$manager_name, countA$grouping))
## this doesn't? 
## Error in fix.by(by.x, x) : 'by' must specify uniquely valid columns

It isn’t particularly pressing: I can just use the merge that works. But I’m honestly confused why specific by.x and by.y doesn’t work. I’ve googled around for it, but I can’t seem to find similar problems. Any thoughts you guys have would be much appreciated.

Leave a Comment