[R] Find all numbers in a certain interval
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Dec 16 13:21:12 CET 2008
Antje wrote:
> Hi,
>
> sorry, but it shouldn't be "different". The result should be the same but I was
> looking if there is a method I can use...
>
> # having a function defined like baptiste proposed:
> isIn <-
> function (interval, x)
> {
> (x > min(interval)) & (x < max(interval))
> }
>
Along the lines I suggested before, I'd suggest a function ordered(...)
(or increasing()?) that could be called as
ordered(-0.5, x, 0.5)
If you do write this, be careful about how you handle recycling of values.
Duncan Murdoch
> #----------------------
>
>
> a <- rnorm(100)
>
> # it's simply more human readable if I can write
>
> which( isIn( c(-0.5, 0.5), a) )
>
> # instead of
>
> which( a > -0.5 & a < 0.5 )
>
> Thanks to baptiste! So there is no method available doing this and I have to
> define this by myself. That's all I wanted to know :-)
>
> Antje
>
>
> markleeds at verizon.net schrieb:
>
>> hi: could you explain EXACTLY what you want to do with the dataframe
>> because it shouldn't be that different ?
>>
>>
>>
>> On Tue, Dec 16, 2008 at 5:09 AM, Antje wrote:
>>
>>
>>> Hi all,
>>>
>>> I'd like to know, if I can solve this with a shorter command:
>>>
>>> a <- rnorm(100)
>>> which(a > -0.5 & a < 0.5)
>>>
>>> # would give me all indices of numbers greater than -0.5 and smaller
>>> than +0.5
>>>
>>> I have something similar with a dataframe and it produces sometimes
>>> quite long commands...
>>> I'd like to have something like:
>>>
>>> which(within.interval(a, -0.5, 0.5))
>>>
>>> Is there anything I could use for this purpose?
>>>
>>>
>>> Antje
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list