Re: [R] join tables in R

From: Petr Savicky <savicky_at_praha1.ff.cuni.cz>
Date: Wed, 04 May 2011 22:13:35 +0200

On Wed, May 04, 2011 at 04:32:14PM +0200, Roccato Alfredo (UniCredit) wrote:
> I'd to match-merge 2 tables in such a manner that I keep all the rows in table 1, but not the rows that are in both table 1 and 2.
> Thank you for your help,
> Alfredo
>

> > master <- data.frame(ID=2001:2011)
> > train <- data.frame(ID=2004:2006)
> > valid <- ???
>
> in this example table valid should have the following
>
> > str(valid)
> Year: int 2001 2002 2003 2007 2008 2009 2010 2011

Hi.

Try the following, which assumes that "train" is a subset of "master".

  master <- data.frame(ID=2001:2011)
  train <- data.frame(ID=2004:2006)
  valid <- master[! (master[, 1] %in% train[ ,1]), , drop=FALSE]

Hope this helps.

Petr Savicky.



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 Thu 05 May 2011 - 06:25:02 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 Thu 05 May 2011 - 13:10:06 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