[R] Rounding to the nearest 5

2009-09-16 Thread Chris Li
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 --

Re: [R] Rounding to the nearest 5

2009-09-16 Thread Bill.Venables
x5 - 5*round(x/5) From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Chris Li [chri...@austwaterenv.com.au] Sent: 16 September 2009 09:15 To: r-help@r-project.org Subject: [R] Rounding to the nearest 5 Hi all, I want

Re: [R] Rounding to the nearest 5

2009-09-15 Thread J Chen
hope this will help for (i in 1:10) { if (i%%52) { 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

Re: [R] Rounding to the nearest 5

2009-09-15 Thread jim holtman
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.c...@mdc-berlin.de wrote: hope this will help for (i in 1:10) {    if (i%%52) {    

[R] Rounding to the nearest 5

2009-08-17 Thread Steve Murray
Dear all, A hopefully simple question: how do I round a series of values (held in an object) to the nearest 5? I've checked out trunc, round, floor and ceiling, but these appear to be more tailored towards rounding decimal places. Thanks, Steve

Re: [R] Rounding to the nearest 5

2009-08-17 Thread Ottorino-Luca Pantani
Steve Murray ha scritto: Dear all, A hopefully simple question: how do I round a series of values (held in an object) to the nearest 5? I've checked out trunc, round, floor and ceiling, but these appear to be more tailored towards rounding decimal places. Thanks, Steve I had a similar

Re: [R] Rounding to the nearest 5

2009-08-17 Thread Erich Neuwirth
mround - function(x,base){ base*round(x/base) } mround(14,5) [1] 15 Steve Murray wrote: Dear all, A hopefully simple question: how do I round a series of values (held in an object) to the nearest 5? I've checked out trunc, round, floor and ceiling, but these appear to be more