Skip to contents

This class represents a common interface for datasets returned from the STATcube REST API and OGD datasets. sc_data obects are usually created with od_table() or sc_table().

Active bindings

data

the raw data. A data.frame that uses codes for all field variables and for all column names. To obtain labeled data, use $tabulate().

language

language to be used for labeling. "en" or "de"

meta

A list containing metadata about the dataset. It has at least the following entries

  • $source is a dataframe with a single row that contains information on the data source.

  • $measures is a dataframe with one row for every measure in the dataset. It contains codes and labels for each measure as well as the number of NAs. Derived classes might add additional columns.

  • $fields is a dataframe with one row for every field in the dataset. It contains codes and labels for each measure as well as the total codes. Derived classes might add additional columns

recode

An object of class sc_recoder that can be used to change labels and perform other recoding operations.

Methods


Method new()

This class is not exported. Use od_table() or sc_table() to initialize objects of class sc_data.

Usage

sc_data$new(data, meta, fields)

Arguments

data, meta, fields

raw data, metadata and field information. Do not use directly but initialize objects with sc_table() or od_table()


Method field()

get information about a specific field. The format of the reurn value is similar to $meta. A data.frame that includes codes and labels for each level of the field.

Usage

sc_data$field(i = 1)

Arguments

i

specifier for the field. Integer or character. If an interger is provided, it should match the row number in $meta$fields. If a character is provided, the field is matched using pmatch() on all available codes and labels.

Examples

x <- od_table("OGD_krebs_ext_KREBS_1")
x$field(1)
x$field("Sex")


Method tabulate()

create a tidy dataset. See sc_tabulate() for details.

Usage

sc_data$tabulate(...)

Arguments

...

arguments that are passed down to sc_tabulate()

Examples

x <- od_table("OGD_krebs_ext_KREBS_1")
x$tabulate("Reporting year", "Sex")


Method total_codes()

Usage

sc_data$total_codes(...)

Arguments

...

key value pairs to define the total codes. Key should be a field code and value a code from $field(i). If empty, it will return a data.frame with all specified total codes. Keys and values can also use labels instead of codes. See examples.

Examples

earnings <- od_table("OGD_veste309_Veste309_1")
earnings$total_codes(Sex = "Sum total", Citizenship = "Total",
                     Region = "Total", `Form of employment` = "Total")
earnings$tabulate("Form of employment")
earnings$tabulate("Sex", "Form of employment")


Method clone()

The objects of this class are cloneable with this method.

Usage

sc_data$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

## create a new sc_data object via od_table()
x <- od_table("OGD_krebs_ext_KREBS_1")

## show data
x$data
#> # A STATcubeR tibble: 46,479 x 5
#>    `C-TUM_ICD10_3ST-0` `C-BERJ-0` `C-BUNDESLAND-0` C-KRE_GES…¹ `F-KRE`
#>  * <fct>               <fct>      <fct>            <fct>         <int>
#>  1 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-1     GESCHLECHT…       2
#>  2 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-2     GESCHLECHT…       8
#>  3 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-2     GESCHLECHT…       2
#>  4 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-3     GESCHLECHT…       6
#>  5 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-3     GESCHLECHT…       2
#>  6 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-4     GESCHLECHT…      12
#>  7 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-4     GESCHLECHT…       2
#>  8 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-5     GESCHLECHT…       4
#>  9 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-6     GESCHLECHT…       5
#> 10 TUM_ICD10_3ST-C00   BERJ-1983  BUNDESLAND-6     GESCHLECHT…       2
#> # … with 46,469 more rows, and abbreviated variable name
#> #   ¹​`C-KRE_GESCHLECHT-0`

## show metadata
x$meta
#> $source
#> # STATcubeR metadata: 1 x 7
#>   code                  label                                    lang 
#>   <chr>                 <chr>                                    <chr>
#> 1 OGD_krebs_ext_KREBS_1 Cancer statistics by reporting year, pr… en   
#> # … with 4 more columns: 'label_de', 'label_en', 'requested', 'scr_version'
#> 
#> $measures
#> # STATcubeR metadata: 1 x 7
#>   code  label                     NAs
#>   <chr> <chr>                   <int>
#> 1 F-KRE Number of records F-KRE     0
#> # … with 4 more columns: 'label_de', 'label_en', 'de_desc', 'en_desc'
#> 
#> $fields
#> # STATcubeR metadata: 4 x 9
#>   code               label                   total_code nitems type   
#>   <chr>              <chr>                   <chr>       <int> <chr>  
#> 1 C-TUM_ICD10_3ST-0  Tumore ICD/10 3-Steller NA             95 Catego…
#> 2 C-BERJ-0           Reporting year          NA             37 Time (…
#> 3 C-BUNDESLAND-0     Province of residence   NA              9 Catego…
#> 4 C-KRE_GESCHLECHT-0 Sex                     NA              2 Catego…
#> # … with 4 more columns: 'label_de', 'label_en', 'de_desc', 'en_desc'
#> 

## ------------------------------------------------
## Method `sc_data$field`
## ------------------------------------------------

x <- od_table("OGD_krebs_ext_KREBS_1")
x$field(1)
#> # STATcubeR metadata: 95 x 10
#>    code              label                                      parsed
#>    <chr>             <chr>                                      <chr> 
#>  1 TUM_ICD10_3ST-C00 <C00> Bösartige Neubildung der Lippe       <C00>…
#>  2 TUM_ICD10_3ST-C01 <C01> Bösartige Neubildung des Zungengrun… <C01>…
#>  3 TUM_ICD10_3ST-C02 <C02> Bösartige Neubildung sonstiger und … <C02>…
#>  4 TUM_ICD10_3ST-C03 <C03> Bösartige Neubildung des Zahnfleisc… <C03>…
#>  5 TUM_ICD10_3ST-C04 <C04> Bösartige Neubildung des Mundbodens  <C04>…
#>  6 TUM_ICD10_3ST-C05 <C05> Bösartige Neubildung des Gaumens     <C05>…
#>  7 TUM_ICD10_3ST-C06 <C06> Bösartige Neubildung sonstiger und … <C06>…
#>  8 TUM_ICD10_3ST-C07 <C07> Bösartige Neubildung der Parotis     <C07>…
#>  9 TUM_ICD10_3ST-C08 <C08> Bösartige Neubildung sonstiger und … <C08>…
#> 10 TUM_ICD10_3ST-C09 <C09> Bösartige Neubildung der Tonsille    <C09>…
#> # … with 85 more rows
#> # … with 7 more columns: 'label_de', 'label_en', 'parent', 'de_desc', 'en_desc', 'visible', 'order'
x$field("Sex")
#> # STATcubeR metadata: 2 x 10
#>   code         label  parsed
#>   <chr>        <chr>  <chr> 
#> 1 GESCHLECHT-1 male   male  
#> 2 GESCHLECHT-2 female female
#> # … with 7 more columns: 'label_de', 'label_en', 'parent', 'de_desc', 'en_desc', 'visible', 'order'

## ------------------------------------------------
## Method `sc_data$tabulate`
## ------------------------------------------------

x <- od_table("OGD_krebs_ext_KREBS_1")
x$tabulate("Reporting year", "Sex")
#> # A STATcubeR tibble: 74 x 3
#>    `Reporting year` Sex    `Number of records F-KRE`
#>  * <date>           <fct>                      <int>
#>  1 1983-01-01       male                       14492
#>  2 1983-01-01       female                     17476
#>  3 1984-01-01       male                       14794
#>  4 1984-01-01       female                     17449
#>  5 1985-01-01       male                       14552
#>  6 1985-01-01       female                     17445
#>  7 1986-01-01       male                       14626
#>  8 1986-01-01       female                     17236
#>  9 1987-01-01       male                       14850
#> 10 1987-01-01       female                     17838
#> # … with 64 more rows

## ------------------------------------------------
## Method `sc_data$total_codes`
## ------------------------------------------------

earnings <- od_table("OGD_veste309_Veste309_1")
earnings$total_codes(Sex = "Sum total", Citizenship = "Total",
                     Region = "Total", `Form of employment` = "Total")
earnings$tabulate("Form of employment")
#> # A STATcubeR tibble: 6 x 6
#>   `Form of employment`         Arith…¹ 1st q…² 2nd q…³ 3rd q…⁴ Numbe…⁵
#> * <fct>                          <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#> 1 "Standard employment "          19.0    12.8    16.2    21.7 1685788
#> 2 "Non-standard employment (t…    15.2    10.2    13.0    17.2  965150
#> 3 "Non-standard employment: p…    15.9    10.7    13.8    18.3  598012
#> 4 "Non-standard employment: f…    16.8    10.2    13.4    18.6  125491
#> 5 "Non-standard employment: m…    12       9      10.1    12.3  141213
#> 6 "Non-standard employment: t…    14.0    11.5    13.5    15.7  100435
#> # … with abbreviated variable names ¹​`Arithmetic mean`,
#> #   ²​`1st quartile`, ³​`2nd quartile (median)`, ⁴​`3rd quartile`,
#> #   ⁵​`Number of employees`
earnings$tabulate("Sex", "Form of employment")
#> # A STATcubeR tibble: 12 x 7
#>    Sex    `Form of employment` Arith…¹ 1st q…² 2nd q…³ 3rd q…⁴ Numbe…⁵
#>  * <fct>  <fct>                  <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
#>  1 Male   "Standard employmen…    20.0   13.5     17.0    22.8 1225839
#>  2 Male   "Non-standard emplo…    16.5   10.5     13.6    18.0  318749
#>  3 Male   "Non-standard emplo…    18.8   11.1     15.2    22.5  119316
#>  4 Male   "Non-standard emplo…    18.3   10.9     14.2    19.6   65377
#>  5 Male   "Non-standard emplo…    12.6    9       10.2    12.6   58175
#>  6 Male   "Non-standard emplo…    14.4   12       13.8    15.9   75880
#>  7 Female "Standard employmen…    16.3   11.1     14.3    18.8  459949
#>  8 Female "Non-standard emplo…    14.6   10.0     12.8    16.8  646401
#>  9 Female "Non-standard emplo…    15.2   10.6     13.5    17.6  478696
#> 10 Female "Non-standard emplo…    15.2    9.68    12.6    16.4   60114
#> 11 Female "Non-standard emplo…    11.6    9.02    10      12.1   83037
#> 12 Female "Non-standard emplo…    13.0   10.4     12.2    14.8   24554
#> # … with abbreviated variable names ¹​`Arithmetic mean`,
#> #   ²​`1st quartile`, ³​`2nd quartile (median)`, ⁴​`3rd quartile`,
#> #   ⁵​`Number of employees`