Subject: Re: [R] Easy way?
From: Martin Maechler (maechler@stat.math.ethz.ch)
Date: Mon 26 Jun 2000 - 18:14:56 EST
Message-ID: <14679.4352.798491.439564@gargle.gargle.HOWL>
>>>>> "Uwe" == Uwe Ligges <ligges@statistik.uni-dortmund.de> writes:
>> Yves Gauvreau wrote:
>>
>> Hi,
>>
>> Say I have this vector x <- sort(rnorm(n)). I'd like to know if
>> there is a nice way to find out the index of the nearest x to say
>> 1.5?
Uwe> I would try:
which(abs(x - 1.5) == min(abs(x - 1.5)))
(and Jan Schelling gives the same solution in "modular" steps
without recomputing "abs(x - 1.5)".)
This is fine and fast enough for moderate data size.
However, since version 1.1
help(which) has
>> See Also:
>> `Logic', `which.min' for the index of the minimum or maximum.
---------
and which.min(), which.max() are really the functions you want to use
here.
Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:24 EST