Skip to contents

A collection of methods that can be used to modify an object of class sc_table by reference. Typical usage is to acces 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


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()

Cheange 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 ommited 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")
#> # A STATcubeR tibble: 2 x 2
#>   SEX    NUMBER
#> * <fct>   <int>
#> 1 female  25862
#> 2 MALE    27580

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()
#> # A data frame: 4 × 2
#>   code       total_code
#>   <chr>      <chr>     
#> 1 C-A11-0    A11-1     
#> 2 C-STAATS-0 STAATS-9  
#> 3 C-VEBDL-0  VEBDL-10  
#> 4 C-BESCHV-0 BESCHV-1  

earnings$tabulate("C-STAATS-0")
#> # A STATcubeR tibble: 8 x 6
#>   Citizenship                  Arith…¹ 1st q…² 2nd q…³ 3rd q…⁴ Numbe…⁵
#> * <fct>                          <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1 "Austrian"                      18.5   12.4     15.9    21.2 2079655
#> 2 "Non-Austrian "                 14.4    9.72    12.3    15.9  571282
#> 3 "EU-28/EWR/Switzerland (wit…    15.2   10.0     12.8    16.6  380327
#> 4 "EU-15/EWR before 2004/Swit…    19.6   11.9     15.9    21.9  122572
#> 5 "EU-13 EU Member States aft…    13.0    9.59    11.9    14.6  257755
#> 6 "Former Yugoslavia (without…    12.8    9.58    12.0    14.7   96065
#> 7 "Turkey"                        12.2    9.35    11.3    14.4   34759
#> 8 "Other"                         13.8    9.07    10.9    14.6   60131
#> # … with abbreviated variable names ¹​`Arithmetic mean`,
#> #   ²​`1st quartile`, ³​`2nd quartile (median)`, ⁴​`3rd quartile`,
#> #   ⁵​`Number of employees`
earnings$recode$visible("C-STAATS-0", "STAATS-8", FALSE)
earnings$tabulate("C-STAATS-0")
#> # A STATcubeR tibble: 7 x 6
#>   Citizenship                  Arith…¹ 1st q…² 2nd q…³ 3rd q…⁴ Numbe…⁵
#> * <fct>                          <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1 "Austrian"                      18.5   12.4     15.9    21.2 2079655
#> 2 "Non-Austrian "                 14.4    9.72    12.3    15.9  571282
#> 3 "EU-28/EWR/Switzerland (wit…    15.2   10.0     12.8    16.6  380327
#> 4 "EU-15/EWR before 2004/Swit…    19.6   11.9     15.9    21.9  122572
#> 5 "EU-13 EU Member States aft…    13.0    9.59    11.9    14.6  257755
#> 6 "Former Yugoslavia (without…    12.8    9.58    12.0    14.7   96065
#> 7 "Turkey"                        12.2    9.35    11.3    14.4   34759
#> # … with abbreviated variable names ¹​`Arithmetic mean`,
#> #   ²​`1st quartile`, ³​`2nd quartile (median)`, ⁴​`3rd quartile`,
#> #   ⁵​`Number of employees`

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