Message-ID: <gmsdck$k42$1@ger.gmane.org>
Date: 2009-02-10T17:26:41Z
From: Keith Jewell
Subject: arithmetic comparison over corresponding values from two vectors
sapply(trgroup, function(x) which(x>=starts & x <=ends))
works for your example data, but there's probably a better way
HTH
KJ
"T Joshi" <tejalonline at gmail.com> wrote in message
news:11417a880902100902w53664a3dq11aee64a963d8383 at mail.gmail.com...
> Hi,
> I have scenario in which I wish to check whether numeric values in one
> array
> falls within the range of numbers defined over corresponding values in two
> other vectors:
>
> starts = c(12,45,67,110)
> ends=c(24, 58,102,150)
>
> trgroup=c(18,87)
>
> The result should be "1,3" , indices of vector starts/ends.
> which(trgroup>=starts & trgroup<=ends) wouldn't give required result.
> I don't want to write a for loop for doing this. Kindly help with ideas.
>
> Josh