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/20000625/be875885/attachment.html
> 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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