Merge ID from two different dataframes

Hi there,

I have two dataframes with the sames ID's, same foods, but different values of intake. The two dataframes both consist of 2184 observations.
What I want to do is to merge the ID's and foodgroups so that I can calculate the difference between the intake over time. I've done it multiple times, but this time it just doesn't work. This is how data looks like (I've also attached it).

df55_1
ID Food Intake
1 Cashewnuts 2
2 Bread 1
3 Cassava 2

df55_3
ID Food Intake
1 Rice 1
2 Potatoes 1
3 Cassava 2

What I have done is this: merge(df55_1, df55_3,by="Fødevare") and also by "ID".
This code gives me a dataset with like a million observations, when only there should be the original 2184.

Can anybody help?

Rkode.pdf (159.9 KB)

There seems to be something strange with your ID's if I am reading that PDF properly. A numeric ID of 1.03013e+12 is unusual to say the least. You may very well be running into numeric accuracy problems which may be what is giving you the millions.

I think we really need reproducible example (reprex) or at least some sample data. Have a look at

A handy way to supply sample data is to use the dput() function. See ?dput. Since you have relatively large data sets then something like head(dput(myfile), 100) for each data.frame will likely supply enough data for us to work with.

Thank you for your answer, I figured it out. Also I find that R is able to work with scientific values.
Thank you!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.