[R] Easy way?

Jan.Schelling@hydro.com Jan.Schelling at hydro.com
Mon Jun 26 09:21:17 CEST 2000



try:

n <- 1000
x <- sort(rnorm(n))
x0 <- 1.5
dx <- abs(x-x0)
which(dx==min(dx))


Jan Schelling



From: cyg at sympatico.ca on 2000-06-25 23:47 GMT



To:   r-help at stat.math.ethz.ch
cc:    (bcc: Jan Schelling/HRE/Hydro)

Subject:  [R] Easy way?



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?

Thanks

YG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://stat.ethz.ch/pipermail/r-help/attachments/20000626/33210d69/att1.htm


More information about the R-help mailing list