How to round up to the nearest 10 (or 100 or X)?

后端 未结 11 1948
执笔经年
执笔经年 2020-11-27 12:20

I am writing a function to plot data. I would like to specify a nice round number for the y-axis max that is greater than the max of the dataset.

Specif

11条回答
  •  再見小時候
    2020-11-27 12:56

    The plyr library has a function round_any that is pretty generic to do all kinds of rounding. For example

    library(plyr)
    round_any(132.1, 10)               # returns 130
    round_any(132.1, 10, f = ceiling)  # returns 140
    round_any(132.1, 5, f = ceiling)   # returns 135
    

提交回复
热议问题