[R] difference between unique() and !duplicated()
Michael Dewey
info at aghmed.fsnet.co.uk
Thu Sep 13 13:00:37 CEST 2007
At 10:47 13/09/2007, T.Lok wrote:
>Yesterday I spend the whole day struggling on how to get the maximum
>value of "y" for every unique value of "x" from the dataframe
>"test". In the R Book (Crawley, 2007) an example of this can be
>found on page 121. I tried to do it this way, but I failed.
>
>In the end, I figured out how to get it working (first order, and
>afterwards use !duplicated()). My question is: why does it not work
>with the unique() function on p. 121 (
>i.e. test[rev(order(x)),][unique(y),]) ?
This is not a direct answer to your question but is not
tapply(y, x, max)
a simpler way to do what you want?
Michael Dewey
http://www.aghmed.fsnet.co.uk
More information about the R-help
mailing list