[R] Is there a way to round numbers up or down to the nearest "natural looking" number?

Jorgy Porgee jorgy.porgee at gmail.com
Wed Sep 16 16:11:18 CEST 2009


Hi all,

Given the following series of numbers:

> t
 [1]  21.85000  30.90410  43.71000  61.82234  87.43999 123.67296
 [7] 174.91997 247.40249 349.91996 494.91815 700.00000

What's the simplest way of formatting them into the nearest "natural
looking" (rounded to nearest multiple of 10) numbers?

So:

t[1] becomes 20
t[2] becomes 30
t[3] becomes 40
t[4] becomes 60
t[5] becomes 90
t[6] becomes 120, etc ?

Thus far I've tried signif(t,2) but that's not working great..

Any help would be much appreciated,

Thanks in advance,

George.




More information about the R-help mailing list