expand | R Documentation |
Expands data.table to dimensions not already present, leaving value columns NA.
expand(dt, expand_cols, id_cols)
dt |
[ |
expand_cols |
[ |
id_cols |
[ |
This function is a wrapper for data.table::CJ()
.
Syntax for example:
dt[CJ(year = 1990:2000, draw = c(1:2), location = "Mexico", unique = T), on = list(location, year)]
dt
with added rows for all combinations of
expand_cols
as specified. In new rows, entries of non-ID columns will
be NA.
dt <- data.table::data.table(
location = c("Mexico"),
year = c(1990:1995),
value = c(0:5)
)
dt <- expand(dt, expand_cols = list(year = 1990:2000, draw = c(1:2)),
id_cols = c("location", "year"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.