[R] matching on multiple minimums

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Oct 28 16:30:28 CEST 2004

Please read ?"==" for comments and a suggested solution.

On Thu, 28 Oct 2004, Barry Taylor wrote:

> Hi,
> I was wondering if someone has witnessed the following
> behavior with matching on multiple minimums in a
> vector:
> If I manually create a vector of doubles:
> test <- c(2.33,11.09,0.02,,6.41)
> I can then run any of the following to retrieve the
> indices of the minimum values (3 and 4 in this case),
> of which there are two (done purposefully):
> which(test==min(test))
> or
> which(!is.na(match(test,min(test))))
> or
> match(test,min(test)) # to see the entire vector
> However, my problem is as follows. I am not manually
> creating a vector to test for multiple minimums but
> rather doing a read.table on a file that contains the
> same data with other columns, etc. I then trim off the
> data from that matrix (there are several identical
> ways to do this):
> unlist(myMatrix[1], use.name=FALSE)
> or
> myMatrix[,1]
> But, running any of the tests listed above only
> returns the index of the last minimum. Both my manual
> vector and vector culled from the matrix appear to me
> to be identical (tested with is.vector, is.numeric,
> is.double, etc), but it will only every return the
> index of the second of the two minimums. Any help
> would be truly appreciated.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list