Re: [R] Comparing entire row sets at once efficiently

From: Dirk Eddelbuettel <>
Date: Thu 28 Sep 2006 - 16:21:44 GMT

I should have known that Gabor would reply within minutes with a nice one-line solution ... :)

On 28 September 2006 at 12:05, Gabor Grothendieck wrote:
| If Comparison and Candidates each have no duplicated rows (which
| is the situation in the example) then try this:
| tail(!duplicated(rbind(Comparison, Candidates)), nrow(Candidates))

Excellent. That will work. Candidates has no dupes because expand.grid() constructs it. Comparison may have dupes, but we can ignore that.

By putting the 'larger set' against we which to compare second, we catch the markers from duplicated(), and then subset via tail(). That's exactly what needed.

Thanks, and chapeau for a very elegant one-liner, Dirk

Hell, there are no rules here - we're trying to accomplish something. 
                                                  -- Thomas A. Edison

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri Sep 29 02:57:35 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 Thu 28 Sep 2006 - 17:30:06 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.