yjtan
yjtan

Reputation: 203

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.

Upvotes: 18

Views: 68636

Answers (1)

Sai Prabhanjan Reddy
Sai Prabhanjan Reddy

Reputation: 536

Before using merge() also see if the classes of two tables you are trying to merge are same. If you try to merge data.table class with data.frame in that case also,it will throw this error.

Upvotes: 14

Related Questions