I need a good vectorization on b of this function:
match(TRUE, b <= a)
For example:
# EDIT
a <- c(2,3,5,6,7,8,10,12) #edited
b <- c(1,3,11)
#output should be: 1 2 8
findInterval(b,a) + 1 # 1 3 8
findInterval(b,a) + 1 - ifelse(!is.na(match(b,a)),1,0) # 1 2 8
EDIT:
findInterval(b,a) + 1
is a partial answer, it works only if the test isb < a
. But i needb <= a
. My guess is :findInterval(b,a) +1 - ifelse(!is.na(match(b,a)),1,0)
, but i would like a better version ofifelse(!is.na(match(b,a)),1,0)
or a better answer.