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,

Steve
_________________________________________________________________
100’s of Nikon cameras to be won with Live Search

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to