sc_recoder: Recode sc_table objects

sc_recoderR Documentation

Recode sc_table objects

Description

A collection of methods that can be used to modify an object of class sc_table by reference. Typical usage is to access the recode binding of an sc_table object and then use method chaining to perform recode operations.

x <- od_table("OGD_krebs_ext_KREBS_1")
x$recode$
  label_field("C-BERJ-0", "de", "JAHR")$
  label_measure("F-KRE", "de", "Anzahl")

See the example section for more details.

Methods

Public methods


Method new()

Create a new recoder instance. This will automatically be performed during the setup of sc_data objects

Usage
sc_recoder$new(x)
Arguments
x

the private environment of an sc_data object


Method label_field()

Change the label of a field variable

Usage
sc_recoder$label_field(field, language, new)
Arguments
field

a field code

language

a language, "de" or "en"

new

the new label


Method label_measure()

Change the label of a measure variable

Usage
sc_recoder$label_measure(measure, language, new)
Arguments
measure

a measure code

language

a language "de" or "en"

new

the new label


Method level()

Change the labels of a level

Usage
sc_recoder$level(field, level, language, new)
Arguments
field

a field code

level

a level code for the field

language

a language "de" or "en"

new

the new label for the level


Method total_codes()

Change the total code for a field

Usage
sc_recoder$total_codes(field, new)
Arguments
field

a field code

new

a level code for the field or NA. Will be used as the new total code. In case of NA, the total code will be unset.


Method visible()

set the visibility of a level. Invisible levels are omitted in the output of ⁠$tabulate()⁠ but don't affect aggregation

Usage
sc_recoder$visible(field, level, new)
Arguments
field

a field code

level

a level code for the field

new

visibility. TRUE or FALSE


Method order()

set the order of levels.

Usage
sc_recoder$order(field, new)
Arguments
field

a field code

new

the new order. A permutation of all level codes for the field. alternatively, an integer vector that defines the permutation.

Examples

x <- od_table("OGD_krebs_ext_KREBS_1")

x$recode$
  label_field("C-KRE_GESCHLECHT-0", "en", "SEX")$
  label_measure("F-KRE", "en", "NUMBER")$
  level("C-KRE_GESCHLECHT-0", "GESCHLECHT-1", "en", "MALE")

x$tabulate("C-KRE_GESCHLECHT-0", "F-KRE")

earnings <- od_table("OGD_veste309_Veste309_1")
earnings$recode$
  total_codes("C-A11-0", "A11-1")$
  total_codes("C-STAATS-0", "STAATS-9")$
  total_codes("C-VEBDL-0", "VEBDL-10")$
  total_codes("C-BESCHV-0", "BESCHV-1")

earnings$total_codes()

earnings$tabulate("C-STAATS-0")
earnings$recode$visible("C-STAATS-0", "STAATS-8", FALSE)
earnings$tabulate("C-STAATS-0")

earnings$recode$
  order("C-A11-0", c("A11-3", "A11-1", "A11-2"))

STATcubeR documentation built on April 3, 2025, 7:31 p.m.