[R] how to get values within a threshold

Zhang Weiwu zhangweiwu at realss.com
Fri Sep 13 18:50:58 CEST 2013



On Fri, 13 Sep 2013, William Dunlap wrote:

> You may want to append -Inf (or 0 if you know the data cannot be
> negative) to the start of your 'values' vector so you don't
> have to write code to catch the cases when a threshold is below
> the range of the values.
>   > findInterval(thresholds, c(0,values,Inf))
>   [1] 1 5 5 5 8
>   > c(0, values, Inf)[.Last.value]
>   [1] 0.000 1.874 1.874 1.874 7.722

Thanks a lot! I'll stick with this method for this project.

Thanks a lot to arun as well, for profiling different methods.



More information about the R-help mailing list