Learn R Programming

sdcTable (version 0.34.1)

contributing_indices: Compute contributing units to table cells

Description

This function maps aggregated table cells back to their constituent microdata. It returns the row indices of the raw input data that contribute to specific cells identified by ids.

Usage

contributing_indices(prob, ids = NULL)

Value

a named list where each element contains integer indices of the contributing rows in the raw microdata.

Arguments

prob

a sdcProblem object created with makeProblem().

ids

a character vector of cell identifiers (strID). If NULL, indices are computed for all cells in the table. Valid identifiers can be found in the strID column of the data frame returned by sdcProb2df().

Examples

Run this code
# load test problem
p <- sdc_testproblem(with_supps = FALSE)
dt <- sdcProb2df(p, dimCodes = "original")

# find the strID for a specific cell (e.g., region "A" and gender "female")
target_id <- dt[region == "A" & gender == "female", strID]

# compute contributing indices for this cell
contr_list <- contributing_indices(prob = p, ids = target_id)

# view the contributing raw data rows
rawData <- slot(get.sdcProblem(p, "dataObj"), "rawData")
rawData[contr_list[[target_id]]]

# compute indices for all cells in the table
all_indices <- contributing_indices(p)

Run the code above in your browser using DataLab