Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given a vector a=[1,2, 3.2, 4, 5] and an element x=3 In vector a, how to find the exact entry which is bigger than x?

Tags:

r

Given a vector a=[1,2, 3.2, 4, 5] and an element x=3 In vector a, how to find the exact entry which is bigger than x? In R, is there any function to do that?

like image 300
user288609 Avatar asked Aug 29 '10 06:08

user288609


2 Answers

> a <- c(1,2, 3.2, 4, 5)
> x <- 3
> a[a > x]
[1] 3.2 4.0 5.0
> min(a[a > x])
[1] 3.2
like image 100
rcs Avatar answered Oct 14 '22 09:10

rcs


the answer...

 min(a[a>3])
like image 29
John Avatar answered Oct 14 '22 11:10

John