digits | R Documentation |
#' @description Default rounding is according to APDE/CHI standards
digits(
digit_data = NULL,
vars_1 = c("result", "lower_bound", "upper_bound", "rse"),
digits_1 = 3,
vars_2 = c("se"),
digits_2 = 4
)
digit_data |
a data.table or data.frame. Must contain the data to be rounded. |
vars_1 |
character vector of indeterminate length. Specifies the variables to be rounded to the number of digits specified by digits_1. If not specified it defaults to c("result", "lower_bound", "upper_bound", "rse") |
digits_1 |
integer representing the number of decimal places to round variables specified in vars_1. The default digits_1 = 3, i.e., 0.123456 >> 0.123. |
vars_2 |
character vector of indeterminate length. Specifies the variables to be rounded to the number of digits specified by digits_2. If not specified it defaults to c("se") |
digits_2 |
integer representing the number of decimal places to round variables specified in vars_2. The default digits_2 = 4 i.e., 0.123456 >> 0.1234. |
By default, this function expects data that has already been formatted for CHI, i.e., data containing result, lower_bound, upper_bound, se, rse. However, the variables and the number of digits to round can be readily specified.
a data.table with appropriate rounding.
set.seed(98104)
dt <- data.table::data.table(
chi_year = rep(2000:2019),
chi_sex = factor(sample(c("Male", "Female"), 20, rep = TRUE, prob = c(0.5, 0.5))),
result = rnorm(20, .75, 0.025),
se = rnorm(20, 0.0258787654654, 0.00001)
)
head(dt) # before
digits(digit_data = dt,
vars_1 = c("result"),
digits_1 = 2,
vars_2 = c("se"),
digits_2 = 5)
head(dt) # after
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.