I know of round() in R, which is able to round off values by passing the number of digits to limit the value to. However, I wish to round up exact values(e.g. 1832-->1850, 1379-->1400) I get to the nearest 50, as shown in the Premium column below.
Is there a function to do this? Thank you!
CodePudding user response:
You may try
x <- c(102, 100, 405, 1187)
round(x/50)* 50
[1] 100 100 400 1200
CodePudding user response:
It might be easier to just use:
library(plyr)
round_any(x, 50)
round(1832, 50)
[1] 1850