[R] Comparing entire row sets at once efficiently

Dirk Eddelbuettel edd at debian.org
Thu Sep 28 18:21:44 CEST 2006


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



More information about the R-help mailing list