[R] Easy way?

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Jun 26 08:32:42 CEST 2000


> 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?

I would try:
 which(abs(x - 1.5) == min(abs(x - 1.5)))


Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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 at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list