[R] Finding unmatched data between two dataframe using several factors

From: Andrew McFadden <Andrew.McFadden_at_maf.govt.nz>
Date: Mon, 12 May 2008 09:40:28 +1200


Hi R users

I am trying to find unmatched data from two dataframes. I would like to find unmatched data based on several factors. For the following data:

dat1 <- data.frame(x = paste("A", 1:6, sep=""),

                  y = c("andy","bob","ciaran","dan", "eion", 
                           "fred")) 

dat1

dat2 <- data.frame(x = paste("A", c(1,2,3,5,6), sep=""),

                  y = c("andy", "bob", "ciaran", 
                           "dan", "zane"),z=c(10,20,30,40,50))  

dat2

I would like to know data that from dat2 that doesn't appear in dat1 based on both the x and y factors ie (A5, dan, 40) and (A6,zane, 50).

I have tried two approaches but have not been successful

? nomatch <- subset(dat1, is.element(?) == FALSE)
? setdiff(dat1$x,dat2$y)

Any thoughts would be great

Regards

Andy

Andrew McFadden MVS BVSc
Incursion Investigator
Investigation & Diagnostic Centres - Wallaceville Biosecurity New Zealand Ministry of Agriculture and Forestry

Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St Upper Hutt

########################################################################
This email message and any attachment(s) is intended solely for the addressee(s) named above. The information it contains is confidential and may be legally privileged. Unauthorised use of the message, or the information it contains, may be unlawful. If you have received this message by mistake please call the sender immediately on 64 4 8940100 or notify us by return email and erase the original message and attachments. Thank you.

The Ministry of Agriculture and Forestry accepts no responsibility for changes made to this email or to any attachments after transmission from the office.

########################################################################

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 11 May 2008 - 21:45:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 11 May 2008 - 23:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive