teraction(Tdate,symbol,TA)))%in%
as.character(with(datB,interaction(Tdate,symbol,TA))),]
# Tdate symbol TA
#3 12/12/12 WQ B8R
A.K.
- Original Message -
From: "Mossadegh, Ramine N."
To: arun
Cc:
Sent: Monday, May 13, 2013 4:17 PM
Subject: RE: [R] how to merge 2 data
Thanks Adam your solution worked perfectly. Thank you all for your
responses.
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-merge-2-data-frame-if-you-want-to-exclude-mutual-obs-tp4666975p4666985.html
Sent from the R help mailing list archive at Nabble.com.
If you create a dummy variable for spets prior to merging, you can keep
only those rows where this value is missing after merging. For example:
# fake data
all <- data.frame(tdate=c(1, 3, 5, 7), symbol=c(2, 4, 6, 8))
spets <- data.frame(tdate=c(1, 3, 5, 2), symbol=c(2, 8, 6, 6))
# create a dummy
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"))
To clarify:
So if in data frame A you have
TdatesymbolTA
12/12/12 AX 123
12/11/12 ZZA4R
12/12/12 WQ B8R
Data frame B
TdatesymbolTA
12/12/12 AX 123
12/11/12 ZZ
In the example below, I am merging 2 data frames & I want everything in the
first one(all)
all2 <- merge(all,spets, by.x=c("tdate","symbol"),
by.y=c("tdate","symbol"),all.x=TRUE)
What if I want to exclude everything in y? I tried below but doesn't seem to
work.
all2 <- merge(all,spets, by.x=c("tda
6 matches
Mail list logo