I am merging two dataframes using a relational key (incident number and incident year), but not all the records match up. I want to be able to review only the records that cannot be merged for each individual dataframe (essentially trying to select records from one dataframe using a multi-value relational key from the other dataframe). The following code shows what I am trying to do. The final two lines of code do not work, but if somebody could figure out a workable solution, that would be great. Thanks. --Markus
incidents = data.frame( INC_NO = c(1,2,3,4,5,6,7,8,9,10), INC_YEAR = c(2006, 2006, 2006, 2007, 2008, 2008, 2008, 2008, 2009, 2010), INC_TYPE = c("EMS", "FIRE", "GAS", "MVA", "EMS", "EMS", "EMS", "FIRE", "EMS", "EMS")) responses = data.frame( INC_NO = c(1,2,2,2,3,4,5,6,7,8,8,8,9,10), INC_YEAR = c(2006, 2006, 2006, 2006, 2006, 2007, 2008, 2008, 2008, 2018, 2018, 2018, 2009, 2010), UNIT_TYPE = c("E2", "E2", "E5", "T1", "E7", "E6", "E2", "E2", "E1", "E3", "E7", "T1", "E7", "E5")) merged_data = merge(incidents, responses, by=c("INC_NO", "INC_YEAR")) relational_key = c("INC_NO", "INC_YEAR") ## following does not work, but I want DF of incidents that did not merge up with responses incidents[incidents[,relational_key] %in% responses[,relational_key],] ## following does not work, but I want DF of responses that did not merge up with incidents responses[responses[,relational_key] %in% incidents[,relational_key],] [[alternative HTML version deleted]] ______________________________________________ R-help@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.