[R] how to merge 2 data frame if you want to exclude mutual obs

Sarah Goslee sarah.goslee at gmail.com
Mon May 13 22:30:31 CEST 2013


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

maybe?

# converted your email to a reproducible example, as you should
# have done - use dput() to provide data, not just copy & paste.

A <- structure(list(Tdate = c("12/12/12", "12/11/12", "12/12/12"),
    symbol = c("AX", "ZZ", "WQ"), TA = c("123", "A4R", "B8R")), .Names
= c("Tdate",
"symbol", "TA"), class = "data.frame", row.names = c(NA, -3L))
B <- structure(list(Tdate = c("12/12/12", "12/11/12"), symbol = c("AX",
"ZZ"), TA = c("123", "A4R")), .Names = c("Tdate", "symbol", "TA"
), class = "data.frame", row.names = c(NA, -2L))

> A[!(A$symbol %in% B$symbol), ]
     Tdate symbol  TA
3 12/12/12     WQ B8R

This isn't a merge problem at all, as you've explained it.

On Mon, May 13, 2013 at 4:22 PM, ramoss <ramine.mossadegh at finra.org> wrote:
> To clarify:
>
> So if in data frame A you have
>
> Tdate            symbol        TA
> 12/12/12      AX               123
> 12/11/12      ZZ                A4R
> 12/12/12      WQ              B8R
>
> Data frame B
> Tdate            symbol        TA
> 12/12/12      AX               123
> 12/11/12      ZZ                A4R
>
> I want to end up w/
> Tdate            symbol        TA
> 12/12/12      WQ              B8R
>
> All obs not in B
>
>
>
-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list