R merge () doesn't work (anymore) as intended

It worked for me before, but now it is not, and I spent two days on it before asking for help here. I have two datasets, one called Access, the other CO2. Each of them has four variables, two of which are common, and I want to use them to combine two data sets. Just to play it, really save, I insert the outputs of head () and str () here:

> head(Access) > head(CO2) xy access xy CO2equ 1 -32.65 83.65 0.00 1 -32.65 83.65 183316.4 2 -36.85 83.55 4481.25 2 -36.85 83.55 173327.8 3 -36.75 83.55 4464.75 3 -36.75 83.55 301413.9 4 -36.65 83.55 4448.25 4 -36.65 83.55 360757.2 5 -36.55 83.55 4431.00 5 -36.55 83.55 409523.5 6 -36.45 83.55 4414.50 6 -36.45 83.55 448302.0 > str(Access) 'data.frame': 2183106 obs. of 3 variables: $ x : num -32.7 -36.8 -36.8 -36.7 -36.5 ... $ y : num 83.7 83.5 83.5 83.5 83.5 ... $ access: num 0 4481 4465 4448 4431 ... - attr(*, "data_types")= chr "N" "N" "N" > str(CO2) 'data.frame': 2183106 obs. of 3 variables: $ x : num -32.7 -36.9 -36.8 -36.7 -36.6 ... $ y : num 83.6 83.5 83.5 83.5 83.5 ... $ CO2equ: num 183316 173328 301414 360757 409523 ... - attr(*, "data_types")= chr "N" "N" "N" 

Now I am trying to use merge () versions. The first of them leads to the empty data.frame data, the second in all rows that exist twice, once for variables from the first data set, and the second to variables from the second data set:

 > M1 = merge(Access, CO2, c("x","y")) > head(M1) [1] xy access CO2equ <0 rows> (or 0-length row.names) > M2 = merge(Access, CO2, by=c("x","y"), all=TRUE) > length(M2$x) [1] 4366212 > head(M2) xy access CO2equ 1 -179.95 -89.95 NA 0 2 -179.95 -89.85 NA 0 3 -179.95 -89.75 NA 0 4 -179.95 -89.65 NA 0 5 -179.95 -89.55 NA 0 6 -179.95 -89.45 NA 0 

Obviously, the corresponding x and y are not recognized as equivalent, but I don't know why. The data types are the same, the values ​​look the same, and worst of all, I did it successfully a few months ago. At that time I was telling the history of the commands, and now, when I just copy and paste it into my R console, it does not work. I tried this in both R 2.13.0 and Revolution R Enterprise 4.3. I am sure that this is not a software bug, but something trivial that I simply overlooked even after I spent about two days on it.

Cheers
Jochen

+4
source share
1 answer

Try doing a round (..., 1) for both x and y before merging.

+3
source

All Articles