round_to_nearest | R Documentation |
It's sometimes useful to round numbers to a predictable range, e.g. when preparing graph axes or perhaps for filtering or presenting data. This function can round numbers to the nearest, say, 0.5.
round_to_nearest(num, to, dir = NULL)
num |
(Numeric) A vector of numbers. |
to |
(Numeric) What interval should |
dir |
(Optional Char: |
A numeric vector.
https://stackoverflow.com/a/8665247/5578429
vec <- c(1.739006, 2, -1.4, 1.05, 1.90, 3.826)
round_to_nearest(vec, 0.5)
#> [1] 1.5 2.0 -1.5 1.0 2.0 4.0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.