split_unknown | R Documentation |
Split unknown groupings according to observed proportion and redistribute.
split_unknown(
dt,
id_cols,
value_cols,
col_stem,
col_type,
mapping,
quiet = FALSE
)
dt |
[ |
id_cols |
[ |
value_cols |
[ |
col_stem |
[ |
col_type |
[ |
mapping |
[ |
quiet |
[ |
[data.table()
]
dt
with unknown groupings split across known groupings, and then removed.
# interval
dt <- data.table::data.table(
age_start = c(0, 1, 2, NA),
age_end = c(1, 2, 3, NA),
population = c(20, 30, 50, 10)
)
dt <- split_unknown(
dt,
id_cols = c("age_start", "age_end"),
value_cols = "population",
col_stem = "age",
col_type = "interval",
mapping = data.table::data.table(age_start = c(0), age_end = c(3))
)
# categorical
dt <- data.table::data.table(
sex = c("male", "female", NA),
population = c(25, 75, 10)
)
dt <- split_unknown(
dt,
id_cols = "sex",
value_cols = "population",
col_stem = "sex",
col_type = "categorical",
mapping = data.table::data.table(
parent = c("all", "all"),
child = c("male", "female")
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.