prepare_data: Prepares the data to be used by the 'mutual' function

View source: R/prepare_data.R

prepare_dataR Documentation

Prepares the data to be used by the mutual function

Description

Takes a tabular object (micro-data or a frequency table) and returns a data.table ready for mutual. The output * stores every analytical variable as a factor; * holds the weight variable under the unified name fw (numeric); * aggregates identical combinations (summing their weights) and drops rows where fw == 0.

Usage

prepare_data(data, vars, fw = NULL, col.order = NULL)

Arguments

data

A tabular object: data.frame, data.table or tibble.

vars

A vector of column names or indices, or the literal "all_vars" to select every column except fw.

fw

(optional) Name or index of the frequency-weight column. Must reference exactly one column. If NULL, a new variable fw = 1 is created.

col.order

(optional) Column(s) used to sort the final table; must be included in vars. Accepts names or indices.

Value

A data.table with classes "mutual.data", "data.frame" and "data.table". The analytical variables are stored in the attribute "vars"; the key is cleared.

Examples


md <- prepare_data(
  DF_Seg_Chile,
  vars = c("csep", "ethnicity", "school", "district"),
  fw   = "nobs"
)
md <- prepare_data(DF_Seg_Chile, vars = "all_vars")
class(md)



mutualinf documentation built on Aug. 24, 2025, 9:08 a.m.