View source: R/Data_handling.R
round_df | R Documentation |
Round the columns of numeric mode type double to specified (default = 6) significant digits.
round_df(x, digits = 6)
x |
A data frame. |
digits |
An integer. See |
Actual signif
function is used for rounding. Note that other
classes might be internally stored as numeric types. Particularly
POSIXct
class is by default stored as integer (rounding does
not apply) but in case of adding (subtracting) double or if displaying
fractional seconds, such date-time information will be internally converted
to the type double (rounding applies). See examples.
A data frame with varnames
and units
attributes.
set.seed(123)
n <- 17520 # number of half-hourly records in one non-leap year
tstamp <- seq(c(ISOdate(2021,3,20)), by = "30 mins", length.out = n)
x <- data.frame(
timestamp = tstamp,
H = rf(n, 1, 2, 1),
LE = rf(n, 1, 2, 1),
qc_flag = sample(c(0:2, NA), n, replace = TRUE)
)
openeddy::varnames(x) <- c("timestamp", "sensible heat", "latent heat",
"quality flag")
openeddy::units(x) <- c("-", "W m-2", "W m-2", "-")
str(x)
r <- round_df(x)
head(r)
str(r) # varnames and units are preserved
# Prevent adding double type to POSIXct as it would lead to rounding:
y <- x
y$timestamp <- y$timestamp - 900 # use 900L instead
head(y)
class(y$timestamp)
is.double(y$timestamp)
head(round_df(y))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.