Skip to content

Merging dataframes

1 message · Sarmah, Chintanu

#
Thanks, Peter, Eivind and Lui

Sorry, I could not explain it properly in the first go. Trying to simplify it here with an example - Say I have two dataframes as below that are not equally-sized data frames:

Table_A:
Email             Name                   Phone
abc at gmail.com<mailto:abc at gmail.com>   John Chan         0909
bcd at yahoo.com<mailto:bcd at yahoo.com>   Tim Ma                    89089
......

Table_B:
Email              Name                 Sex        Phone
abc at gmail.com<mailto:abc at gmail.com>    John Chan        M                 0909
khn at hotmail.com<mailto:khn at hotmail.com>           Rosy  M               F                   7779
.....

Now, I have used -
merge (Table_A, Table_B, by="Email", all = FALSE))

- to find only the rows that match from these data frames.

Further, I am also interested (using "Email" as the common key) which rows from Table_A did not match with Table_B.
I am not sure how to do here.

 Thanks.
On 1 May 2018, at 9:35 pm, Chintanu <chintanu at gmail.com<mailto:chintanu at gmail.com>> wrote:
---------- Forwarded message ----------
From: peter dalgaard <pdalgd at gmail.com<mailto:pdalgd at gmail.com>>
Date: Tue, May 1, 2018 ar-help at r-project.org<mailto:r-help at r-project.org>t 9:05 PM
Subject: Re: [R] Merging dataframes
To: Rui Barradas <ruipbarradas at sapo.pt<mailto:ruipbarradas at sapo.pt>>
Cc: Chintanu <chintanu at gmail.com<mailto:chintanu at gmail.com>>, R help <r-help at r-project.org<mailto:r-help at r-project.org>>


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
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk<mailto:pd.mes at cbs.dk>  Priv: PDalgd at gmail.com<mailto:PDalgd at gmail.com>










IMPORTANT NOTICE: The information in this email (and any attachments) is confidential. If you are not the intended recipient, you must not use or disseminate the information. If you have received this email in error, please immediately notify me by "Reply" command and permanently delete the original and any copies or printouts thereof. Although this email and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by AIA Group Limited or its subsidiaries or affiliates either jointly or severally, for any loss or damage arising in any way from its use.