Add a new data matrix to a subtable within a procr_table object or retrieve
it. All data matrices within a subtable share the same row and column
structure. This is the primary way to add additional measures (e.g. standard
errors, confidence intervals) to an existing table and to retrieve them for
inspection or further processing.
Usage
add_data(
tab,
mat,
label,
subtable = NULL,
overwrite = FALSE,
rows = NULL,
cols = NULL,
call_user = NULL,
call_internal = NULL
)
get_data(tab, label, subtable = NULL)Arguments
- tab
A
procr_tableobject.- mat
A matrix or sparse matrix to add. Will be coerced to a dense matrix via
as.matrix(). Must have dimensions matching the referenced row and column structures.- label
Character scalar. Name for the matrix (e.g. "se", "ci_lower").
- subtable
Reference to the subtable within
tabto whichmatshould be added. Can beNULL(default) if only one subtable exists, else either a character scalar reference to the subtable name or a numeric scalar reference to its position.- overwrite
Logical scalar. If
TRUE, allows overwriting existing data with the same label. IfFALSE(default), throws an error iflabelalready exists intab$data.- rows
A
procr_varformat, if none exists in the 'dims$rows' slot of thesubtable, or elseNULL(default).- cols
A
procr_varformat, if none exists in the 'dims$cols' slot of thesubtable, or elseNULL(default).- call_user
A
call, if none exists in the 'call$user' slot of thesubtable, or elseNULL(default).- call_internal
A
call, if none exists in the 'call$internal' slot of thesubtable, or elseNULL(default).
Value
set_* returns the modified procr_table object with the new data
matrix added. get_* returns the specified matrix.
Examples
if (FALSE) { # \dontrun{
# Create base table
tab <- create_table_mean(eusilc, region_f ~ gender_f, var = eqIncome)
# Add standard errors
se_mat <- compute_se(tab) # User function
tab <- add_data(tab, se_mat, label = "se")
get_data(tab, label = "se")
} # }