[R] difference between unique() and !duplicated()

Michael Dewey
2007-09-13T11:00:37Z

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