Reputation: 285
I would like to check the elements of the vector
x = c(0.0153, 0.1352, 0.2820, 0.4629, 0.6944, 0.8919,
1.0638, 1.2458, 1.4068, 1.5969, 1.7700, 1.9024,
2.0144, 2.1143, 2.2286, 2.3453, 2.5096, 2.7499,
3.0299, 3.5061)
is between the elements of the vector
y =c(0.0000, 0.0917, 0.2174, 0.3087, 0.4151, 0.8984,
1.0921, 1.1579, 1.3803, 1.3806, 1.6234, 1.8682,
2.0565, 2.2194, 2.285, 2.4183, 2.4463, 2.512,
2.7964, 3.0766, 3.5061)
which means that is the first element of vector x
between the first and second elements of the vector y
or not, ... but not checkig the last element x
.
Is there anymethod to solve it?
Upvotes: 0
Views: 430
Reputation: 7475
you could probably remove the for loop
x[(x>y[-length(y)])&(x<y[-1])]
and add the last x value. Im not clear if you want the last x or not?
or
x[!((x-y[-length(y)])*(y[-1]-x)<0)]
if you want the last x
Upvotes: 2