tabulate_micro_data: tabulate grouped data with all margins, handling hierarchical...

View source: R/tabul_group_fun.R

tabulate_micro_dataR Documentation

tabulate grouped data with all margins, handling hierarchical variables

Description

tabulate grouped data with all margins, handling hierarchical variables

Usage

tabulate_micro_data(
  df,
  cat_vars = NULL,
  hrc_vars = NULL,
  pond_var = NULL,
  resp_var = NULL,
  marge_label = "Total"
)

Arguments

df

data.frame or data.table

cat_vars

vector of categorical variables but not hierarchical

hrc_vars

named list (name = VAR final name, value = VAR current names)

pond_var

weight (NULL if no weight is used)

resp_var

vector of response variables (NULL to only compute frequency table)

marge_label

label of margins (applied to all cat and hrc variables)

Value

a tibble

Examples

library(data.table)

data("indiv_dt")

#Non hierarchical variables
res_all_dtp <- tabulate_micro_data(
  df = indiv_dt,
  #categorical but not hierarchical variables
  cat_vars = c("A10", "SIZE","CJ"),
  #weight var
  pond_var = "WEIGHT",
  #response variable
  resp_var = "TURNOVER",
  # Labels of the margins
  marge_label = "Total"
)
str(res_all_dtp)

#With one hierarchical variable
res_all_dtph <- tabulate_micro_data(
  df = indiv_dt,
  #categorical but not hierarchical variables
  cat_vars = c("SIZE","CJ"),
  #categorical nested variables
  hrc_vars = list(ACTIVITY = c("A10","A21")),
  pond_var = "WEIGHT",
  resp_var = c("TURNOVER","PRODUCTION"),
  marge_label = "Total"
)
str(res_all_dtph)


InseeFrLab/rtauargus documentation built on Feb. 25, 2025, 6:32 a.m.