Reputation: 21625
Suppose I have a number like 123542.52. How do I display that number to the nearest thousand? In this example, 124 should be displayed.
Upvotes: 0
Views: 3376
Reputation: 44525
Just use a negative digits argument in round():
round(123542.52, -3)/1000
# [1] 124
As described in ? round
:
Rounding to a negative number of digits means rounding to a power of ten, so for example
round(x, digits = -2)
rounds to the nearest hundred.
Upvotes: 5
Reputation: 8818
You could do this:
x = 123542.52
y = signif(x,3)
y <- as.numeric(gsub("0","",y))
Upvotes: 0