Re: [R] which.max2()

From: Esmail Bonakdarian <esmail.js_at_gmail.com>
Date: Fri, 09 May 2008 13:31:54 -0400

Marc Schwartz wrote:
>
> I might be tempted to take a more generic approach, where one can
> provide an argument to the function to indicate that I want the 'top x'
> maximum values and to give the user the option of returning the indices
> or the values themselves.
>
> Perhaps:
>
> which.max2 <- function(x, top = 1, values = FALSE)
> {
> if (values)
> rev(sort(x))[1:top]
> else
> order(x, decreasing = TRUE)[1:top]
> }

Very cool too! .. Thanks Marc. Again, I did not get this from the order documentation (ie that it manipulate index values rather than the values themselves). Great to see examples.

Best,
Esmail



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 09 May 2008 - 18:13:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 09 May 2008 - 18:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive