[R] Count between interval

Peter Ehlers ehlers at ucalgary.ca
Mon Feb 22 17:55:21 CET 2010


And as long as the interval is symmetric about zero:

sum(abs(x) <= 2)
[1] 6

  -Peter Ehlers

On 2010-02-22 9:18, Jorge Ivan Velez wrote:
> Hi,
>
> Here is a suggeston:
>
>
>> x<- c(-1.3, 1, -1.5, -1, 1.5, -2.5, 3, -0.5)
>> sum(x>=-2&  x<=2)
> [1] 6
>
> HTH,
> Jorge
>
>
> On Mon, Feb 22, 2010 at 9:49 AM, Bosken<>  wrote:
>
>>
>> Hi all,
>>
>> I take a simple dataset like this:
>>
>> -1.3
>> 1
>> -1.5
>> -1
>> 1.5
>> -2.5
>> 3
>> -0.5
>>
>> Now I want to count how many values there are between -2 and 2.
>>
>> The answer here would be 6.
>>
>> Can anyone do this with R?
>>
>> Thank you in advance.
>>
>> Gr. Bosken
>> --
>> View this message in context:
>> http://n4.nabble.com/Count-between-interval-tp1564537p1564537.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list