0
votes

I have two dataframes, df1 with 76349 rows and 4 columns (long, lat, country, year), and df2 with 2999 rows and 2 columns (long, lat). All the coords in df2 are mutual coordinates with df1. I need obtain the values of country and year of df1 for the same values of df2. I have trying solve using merge function. Apparently the output are correct, showing the values of country and year in df1 for coords identical of df2, however the number of rows in output is bigger than df2 (data refference). I tried to remove NA values and duplicated values, but the output remains bigger than df2.

How can I obtain values from country and years in df1 for the exactly values in df2?

I use the comand:

x = merge(df1,df2, by=c('long','lat'))

Thank for helping!

Here: link for data download. https://www.dropbox.com/sh/zr9n56by0qs3h4l/AABjUO6wVi4zzrY2LWHH5P65a?dl=0

1
you need an all argument, like x = merge(df1,df2, by=c('long','lat'), all.y=TRUE) (i think) - SymbolixAU

1 Answers

0
votes

The package dplyr has several join options that may be helpful.
If I understand your question, the function 'inner_join' in that package should return what you want, i.e.:

library(dplyr)
x = inner_join(df2, df1)