matrix_to_dt | R Documentation |
Convert demographic data (can be by age and/or sex) between two
data formats, [data.table()
] and [matrix()
]. When stored in matrix
form the data is required to be square (ie. same number of ages in every
year).
matrix_to_dt(
mdt,
year_right_most_endpoint,
age_right_most_endpoint = Inf,
gen_end_interval_col = TRUE,
value_col = "value",
validate_arguments = TRUE
)
dt_to_matrix(
dt,
id_cols = c("year_start", "year_end", "sex", "age_start", "age_end"),
value_col = "value",
validate_arguments = TRUE
)
mdt |
[ |
year_right_most_endpoint |
[ |
age_right_most_endpoint |
[ |
gen_end_interval_col |
[ |
value_col |
[ |
validate_arguments |
[ |
dt |
[ |
id_cols |
[ |
data.table format: When data is in data.table format then it must have a column for 'year_start' and 'year_end', if the data is sex-specific it must have a column for 'sex', and if the data is age-specific it must have columns for 'age_start' and 'age_end.
matrix format: When data is in matrix format, columns represent the start of each calendar year interval, rows represent the start of each age interval. If the data is sex specific each sex will have a separate matrix stored in a named list (names corresponding to each sex). If the data is age specific rows will be labeled with a numeric representing the start of the age group.
matrix_to_dt
returns a [data.table()
] in data.table format as
described in the details section. dt_to_matrix
returns a matrix of list of
matrices as described in the details section.
output_matrix <- demCore:::dt_to_matrix(thailand_initial_estimates$survival)
output_dt <- demCore:::matrix_to_dt(output_matrix, year_right_most_endpoint = 2000)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.