Re: [R] which.max2()

2008-05-09 Thread Esmail Bonakdarian
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,

Re: [R] which.max2()

2008-05-09 Thread Esmail Bonakdarian
Dimitris Rizopoulos wrote: try this: v <- rnorm(10) v order(v, decreasing = TRUE)[1:2] Wow .. that is slick! First I thought, wait .. I don't want to reorder the elements, but this doesn't - it just returns the index values in order. I don't really get that from reading the documentation, it's

Re: [R] which.max2()

2008-05-09 Thread Marc Schwartz
on 05/09/2008 08:07 AM Esmail Bonakdarian wrote: Hello, which.max() only returns one index value, the one for the maximum value. If I want the two index values for the two largest values, is this a decent solution, or is there a nicer/better R'ish way? max2 <-function(v) { m=which.max(v)

Re: [R] which.max2()

2008-05-09 Thread Dimitris Rizopoulos
ttp://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "Esmail Bonakdarian" <[EMAIL PROTECTED]> To: Sent: Friday, May 09, 2008 3:07 PM Subject: [R] which.max2() Hello, which.max() only returns one index val

[R] which.max2()

2008-05-09 Thread Esmail Bonakdarian
Hello, which.max() only returns one index value, the one for the maximum value. If I want the two index values for the two largest values, is this a decent solution, or is there a nicer/better R'ish way? max2 <-function(v) { m=which.max(v) v[m] = -v[m] m2=which.max(v) result=c(m,