Re: [R] Retain only those records from a dataframe that exist in another dataframe

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 08 Aug 2006 - 06:14:05 EST

"Mark Na" <mtb954@gmail.com> writes:

> Dear R community,
>
> I have two dataframes "first" and "second" which share a unique identifier.
>
> I wish to make a new dataframe "third" retaining only the rows in
> "first" which also occur in "second".
>
> I have tried using merge but can't seem to figure it out. Any ideas?

Doesn't sound like a merge problem. Will this do it?:

first[first$ID %in% second$ID,]

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch 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 Tue Aug 08 11:39:04 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 08 Aug 2006 - 12:20:52 EST.

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