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 _________________________________________________________________ icons.
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 problem in the past Take a look at http://tolstoy.newcastle.edu.au/R/e4/help/08/05/11017.html and to the replies -- Ottorino-Luca Pantani, Universit? di Firenze Dip. Scienza del Suolo e Nutrizione della Pianta P.zle Cascine 28 50144 Firenze Italia Tel 39 055 3288 202 (348 lab) Fax 39 055 333 273 OLPantani at unifi.it http://www4.unifi.it/dssnp/
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 tailored towards rounding decimal places. > > Thanks, > > Steve > > > > _________________________________________________________________ > > icons. > > ______________________________________________ > 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. > >-- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459
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-tp25463367p25463367.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
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.
Reasonably Related Threads
- Is there in R a function equivalent to the mround, as found in most spreadsheets?
- dividing a dataframe column by different constants
- Rearranging long tables, Sweave, xtable, LaTeX
- again on ubuntu 7.10 and amd64
- R code to reproduce (while studying) Bates & Watts 1988