Description Usage Arguments Value Examples
Round values to a given precision
1 |
x |
vector of values, can be numeric, POSIXct, Date. |
precision |
precision at which to round, in the unit of |
f |
rounding function: |
A vector of the same length as x, rounded to precision.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | roundp(1:10, 1)
roundp(1:10, 4)
roundp(1:10, 4, floor)
roundp(1:10, 4, ceiling)
roundp(Sys.time() + 1:5, 3)
roundp(Sys.time() + 1:5, 5, floor)
# round on the hour
roundp(Sys.time(), 3600)
roundp(Sys.Date() + 1:5, 2)
roundp(Sys.Date() + 1:5, 2, floor)
# useful to bin data over a coordinate (or time)
library("dplyr")
d %>%
# bin depth over 10m
mutate(bin=roundp(depth, 10)) %>%
# average each variables in each bin
group_by(bin) %>% summarise_all(mean)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.