0

I am looking for something partially along the line of this

Round number by rounding units in R

I want to have a function which automatically rounds a number smaller than 1 to a non-zero value e.g.

0.0043----> 0.004

0.087 ---> 0.09

but in general I do not know how many zero decimals I have in each number, so I cannot resort to a plain vanilla round(). Can anyone help me out?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
larry77
  • 1,309
  • 14
  • 29
  • 2
    Do you mean [Significant Digits](https://stackoverflow.com/questions/21526038/how-to-format-numbers-in-r-specifying-the-number-of-significant-digits-but-keep)? – SmokeyShakers Apr 30 '21 at 12:23
  • 1
    I assume that the problem is that you can not formalize the criteria to the rounding. Try to specify what exactly you need: the number of decimals, the number of non-zero digits etc. Probably the answer will vary for different data fields – asd-tm Apr 30 '21 at 12:25
  • https://stackoverflow.com/questions/42959616/rounding-significant-figures-in-r – maarvd Apr 30 '21 at 12:26
  • Indeed significant digits are the way to go for me! Thanks. – larry77 May 03 '21 at 11:23

0 Answers0