I have two dataframes:
df1: My main dataset with an address column
df2: A database containing latitudes and longitudes plus and address column
I want to merge two columns over from df2 to my df1.
df1:
ID VAR1 VAR2 VARX Address
1 7 2 x Road 1, 1234 City
2 8 0 y Road 4, 1234 City
3 6 2 x Road 5, 1234 City
4 7 2 x Road 6, 1234 City
5 4 1 y Road 10, 1234 City
6 1 2 x Road 11, 1234 City
df2:
Address Latitude Longitude
Road 1, 1234 City 12,67 56,78
Road 2, 1234 City 12,66 55,67
Road 3, 1234 City 12,45 55,10
Road 4, 1234 City 12,10 55,20
Road 5, 1234 City 11,50 55,30
Road 6, 1234 City 12,34 55,32
Road 7, 1234 City 12,89 55,40
Road 8, 1234 City 12,77 55,45
Road 9, 1234 City 11,67 55,67
Road 10, 1234 City 11,90 55,78
Road 11, 1234 City 11,12 56,59
So my new dataframe would look like this:
new dataframe, df3:
ID VAR1 VAR2 VARX Address Latitude Longitude
1 7 2 x Road 1, 1234 City 12,67 56,78
2 8 0 y Road 4, 1234 City 12,10 55,20
3 6 2 x Road 5, 1234 City 11,50 55,30
4 7 2 x Road 6, 1234 City 12,34 55,32
5 4 1 y Road 10, 1234 City 11,90 55,78
6 1 2 x Road 11, 1234 City 11,12 56,59
I've tried a left_join, but it only returns NA.
df3 <- left_join(df1, df2, by = c("Address"))
EDIT: SOLVED Apprently I had some wrong spaces in one of my address columns. The code above does work.
dput(df1)
anddput(df2)
? – brettljausn