[R] looking for setdiff equivalent on dataset

Hadley Wickham hadley at rice.edu
Thu Jul 29 23:16:21 CEST 2010


> Well, here's one way that "might" work (explanation below):
>
> The ideas is to turn each row into a character vector and then work with the
> two character vectors.
>
>> bigs <- do.call(paste,TheBigOne)
>> ix <-  which(bigs %in% setdiff(bigs,do.call(paste,TheLittleOne)))
>> TheBigOne[ix,]
>
> However, this may not work if the data frame contain calculated numeric
> values which theoretically (infinite precision) are equal but are not
> exactly due to finite precision. For example, try:
>
>> 0 %in% pi/2
>
> If this is what you have, then you have to do something fancier working
> directly with the numeric values.

That's basically what the plyr code does (except it converts it into
integers) and is pretty efficient ;)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list