Re: [R] how to get the position of a vector-value

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 29 Jul 2008 21:17:11 -0400

?findInterval

> x <- c(1.0,1.2,1.4,1.6,1.8,2.0)
> findInterval(1.4,x)

[1] 3
> findInterval(1.5,x)

[1] 3
> findInterval(10,x)

[1] 6

On Tue, Jul 29, 2008 at 8:32 PM, Jörg Groß <joerg_at_licht-malerei.de> wrote:
> I am searching for a way to get nearest position of a number in a vector
> from a search-value.
>
> So perhaps if I have this vector:
> 1.0 1.2 1.4 1.6 1.8 2.0
>
> I want to get the position of a special number.
>
> with match(1.4 ,x), I get "3" for position three.
>
> But now I want the nearest number in that vector from perhaps 1.5 (the
> mean).
>
>
>
> I tried it with sequences:
> match(seq(from=1.1, to=1.6, by=.1),x)
>
> but what I get is:
> [1] NA NA NA NA NA 4
> (instead of (NA 2 NA 3 NA 4).
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 30 Jul 2008 - 01:20:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jul 2008 - 03:33:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive