[R] compare two data frames of different dimensions and only keep unique rows
Rui Barradas
rui1174 at sapo.pt
Mon Feb 27 19:43:38 CET 2012
Hello,
>
> In fact, the only three unique rows are these ones:
>
> Product Price Nbr.Lots
> Cocoa 2440 5
> Cocoa 2450 1
> Cocoa 2440 6
>
The code below doesn't give the three in one step.
(ixmat <- apply(reported, 1, function(x) apply(exportfile, 1, function(y)
any(x != y))))
reported[apply(ixmat, 2, all), ]
exportfile[apply(ixmat, 1, all), ]
But it does give all three.
Problem: it's inefficient. If n1 <- nrow(reported) and n2 <-
nrow(exportfile),
to form the index matrix alone it will make ncol times n1*n2 comparisons.
And the matrix dims are n1, n2 ...
Anyway, I hope it gives ideas,
Rui Barradas
--
View this message in context: http://r.789695.n4.nabble.com/compare-two-data-frames-of-different-dimensions-and-only-keep-unique-rows-tp4425379p4425605.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list