[R] Rounding to the nearest 5

jim holtman jholtman at gmail.com
Wed Sep 16 02:49:42 CEST 2009


you can also use:

round(x / 5) * 5

> for (i in 1:20) cat(round(i / 5) * 5, ' ')
0  0  5  5  5  5  5  10  10  10  10  10  15  15  15  15  15  20  20  20  >


On Tue, Sep 15, 2009 at 8:08 PM, J Chen <jiaxuan.chen at mdc-berlin.de> wrote:
>
> hope this will help
>
> for (i in 1:10) {
>    if (i%%5>2) {
>    print((i%/%5+1)*5)
>    }
>    else {
>    print((i%/%5)*5)
>    }
> }
>
> Jimmy
>
>
> Chris Li wrote:
>>
>> Hi all,
>>
>> I want to round my values to the nearest 5.
>>
>> For example, if I have a value of 11, I want R to round it to 10.
>>
>> I have been searching for this command on the web and in the help file,
>> but I couldn't find anything useful.
>>
>> Any help would be greatly appreciated.
>>
>> Many thanks,
>> Chris
>>
>
> --
> View this message in context: http://www.nabble.com/Rounding-to-the-nearest-5-tp25463367p25463805.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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list