R merge is duplicating row

Hello
Please help: i 'm merging two dataset and the configuration makes that 'merge' function is duplicating rows (multiplying row between both matrix). Here is a sample to merge foo1 with foo2 to get foo3:

foo1:
Key code
103 50160
103 50190

foo2:
Key factor
103 9
103 0
103 0
103 12
103 8
103 21

foo3: merge(foo1, foo2, by = "Key")
Key factor
103 9
103 9
103 0
103 0
103 0
103 0
103 8
103 8
103 21
103 21
103 12
103 12


Thank you!

What result do you want to get?

Hello

I apologise. I realize that i was not clear enough. Anyway.
If possible i have a question: Once i estimate for example few models (say model1, model2 etc.) I select the one with the highest R2. I do:
best <- noquote(results[(which.max(na.omit(results)$R2)),1][[1]])
But once i call the "best" i have only the name of the model ('model1') but not the estimation associated with the model as if for R it is a string. Do you have an opinion please? Thank you.

Hi Marco,

If you have a new question that is unrelated to your original, would you mind posting it as a separate question? Folks use this site for help with specific questions, and if one question is hidden inside another, it makes it difficult to track down answers.

Thanks.

Hello,

You are right. I'm sorry.

Thank you very much.

1 Like

The answer of merge() is as expected. The join key is neither unique in the left nor in the right table.

Thank you for responding.