Re: [R] Matching Up Values

From: Steve Murray <>
Date: Sun, 20 Jul 2008 17:29:21 +0000

Hmm, I'm having a fair few difficulties using 'merge' now. I managed to get it to work successfully before, but in this case I'm trying to shorten (as oppose to lengthen as before) a file in relation to a 'master' file.

These are the commands I've been using, followed by the dimensions of the files in question - as you can see, the row numbers of the merged file don't correlate to that of the 'coordinates' file (which is what I'm aiming to get 'merged' equal to):

> merge(PopDens.long, coordinates, by=c("Latitude","Longitude"), all = TRUE) -> merged
> dim(PopDens.long); dim(coordinates); dim(merged)

[1] 67870     3
[1] 67420     2
[1] 69849     3

One thing I tried was swapping the order of the files in the merge command, but this causes 'merged' to have the same number of rows (69849).

Something else I tried was to leave out the 'all = TRUE' command, as I'm essentially attempting the shorten the file, but this makes the output file *too* short! (65441 as opposed to the intended 67420). Again, the same applies when the order of the input files are swapped.

> merge(PopDens.long, coordinates, by=c("Latitude","Longitude")) -> merged
> dim(PopDens.long); dim(coordinates); dim(merged)

[1] 67870     3
[1] 67420     2
[1] 65441     3

Am I doing something obviously wrong? I'm pretty certain that 'coordinates' is a subset of 'PopDens.long' - so there should be equal numbers of common values when merged.

Is there perhaps a more suitable function I could use, or a way of performing checks to see where I might be going wrong?!

Many thanks,


100ís of Nikon cameras to be won with Live Search mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sun 20 Jul 2008 - 17:32:09 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 20 Jul 2008 - 18:32:06 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive