[R] Merge data by coordinates

Michal Kubista michal.kubista at nielsen.com
Tue Oct 18 15:59:14 CEST 2016


Dear Milu,
If your objective is to match the places from one table to the nearest
place in the second table, you can generally use knn algorithm for 1
nearest neighbourhood.
But please, check what David suggests first.

Best regards,
Michal

2016-10-16 19:24 GMT+02:00 David Winsemius <dwinsemius at comcast.net>:

>
> > On Oct 16, 2016, at 6:32 AM, Miluji Sb <milujisb at gmail.com> wrote:
> >
> > Dear all,
> >
> > I have two dataframe 1 by latitude and longitude but they always do not
> > match. Is it possible to merge them (e.g. nearest distance)?
> >
> > # Dataframe 1
> > structure(list(lat = c(54L, 55L, 51L, 54L, 53L, 50L, 47L, 51L,
> > 49L, 54L), lon = c(14L, 8L, 15L, 7L, 6L, 5L, 13L, 5L, 13L, 11L
> > ), PPP2000_40 = c(4606, 6575, 6593, 7431, 9393, 10773, 11716,
> > 12226, 13544, 14526)), .Names = c("lat", "lon", "PPP2000_40"), row.names
> =
> > c(6764L,
> > 8796L, 8901L, 9611L, 11649L, 12819L, 13763L, 14389L, 15641L,
> > 16571L), class = "data.frame")
> >
> > # Dataframe 2
> > structure(list(lat = c(47, 47, 47, 47, 47, 47, 48, 48, 48, 48
> > ), lon = c(7, 8, 9, 10, 11, 12, 7, 8, 9, 10), GDP = c(19.09982,
> > 13.31977, 14.95925, 6.8575635, 23.334565, 6.485748, 24.01197,
> > 14.30393075, 21.33759675, 9.71803675)), .Names = c("lat", "lon",
> > "GDP"), row.names = c(NA, 10L), class = "data.frame")
>
> I think you should first do this:
>
> plot(d1$lat,d1$lon)
> points(d2$lat,d2$lon, col="red")
>
> And then respond to my suggestion that this is not a well-posed computing
> problem. Explain why the red dots should have a 1-1 relationship with the
> black dots.
>
>
> --
> David.
>
> >
> > Thank you so much!
> >
> > Sincerely,
> >
> > Milu
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list