Skip to content

Merging dataframes

4 messages · Chintanu, Rui Barradas, Peter Dalgaard +1 more

#
Hi,


May I please ask how I do the following in R. Sorry - this may be trivial,
but I am struggling here for this.



For two dataframes (A and B), I wish to identify (based on a primary
key-column present in both A & B) -

1. Which records (rows) of A did not match with B, and



2. Which records of B did not match with A ?



I came across a setdt function while browsing, but when I tried it, it says
- Could not find function "setdt".



Overall, if there is any way of doing it (preferably in some simplified
way), please advise.


Many thanks in advance.


regards,

Tito
#
Hello,

Is it something like this that you want?

x <- data.frame(a = c(1:3, 5, 5:10), b = c(1:7, 7, 9:10))
y <- data.frame(a = 1:10, b = 1:10)

which(x != y, arr.ind = TRUE)


Hope this helps,

Rui Barradas
On 5/1/2018 11:35 AM, Chintanu wrote:
#
I'd expect more like

setdiff(A$key, B$key) 

and vice versa. Or, if you want the actual rows

A[!(A$key %in% B$key),]

or for the row numbers

which(!(A$key %in% B$key))


-pd

  
    
#
On Tue, 1 May 2018, Chintanu wrote:

            
Dear Tito,

Please provide your R-code so we can reproduce your data (and your 
setdt-error).

Best,

Eivind K. Dovik
Bergen, NO