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,
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
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)
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
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,
5 matches
Mail list logo