sc_tabulate {STATcubeR}R Documentation

Turn sc_data objects into tidy data frames

Description

sc_tabulate() extracts the data in the table and turns it into a tidy data.frame. It applies labeling of the data and transforms time variables into a Date format if they satisfy certain 'STATcube' standards.

sc_tabulate(table, ...) is just an alias for table$tabulate(...) and was added so this rather complicated method can have a separate documentation page. It is recommended to use the table$tabulate() syntax

the ... argument decides which measures and/or fields should be included in the output. If no measures are given, all measures are included. The same is true for fields.

Usage

sc_tabulate(
  table,
  ...,
  .list = NULL,
  raw = FALSE,
  parse_time = TRUE,
  recode_zeros = inherits(table, "sc_table"),
  language = NULL,
  sort = FALSE
)

Arguments

table

An object of class sc_data

...

Names of measures and/or fields

.list

allows to define the arguments for ... as a character vector.

raw

If FALSE (the default), apply labeling to the dataset. Otherwise, return codes.

parse_time

Should time variables be converted into a Date format? Ignored if raw is set to TRUE.

recode_zeros

turn zero values into NAs

language

The language to be used for labeling. By default, the dataset language (table$language) is used.

sort

If TRUE, the resulting data will be sorted by all provided field values

Details

Aggregation is done as follows

The ellipsis (...) supports partial matching of codes and labels. See Examples

For objects of class sc_table two additional operations are performed.

Value

a data.frame

See Also

sc_table_class

Examples

############################ OGD Data #######################################

table <- od_table("OGD_veste309_Veste309_1")

# no arguments -> same output as `table$data`
table$tabulate()

# provide some fields -> aggregate to keep only these fields
table$tabulate("Sex", "Citizenship")

# provide some measures -> drop all other measures from the output
table$tabulate("Arithmetic mean")

# mixture of measures and fields  -> keep exactly those columns
table$tabulate("Sex", "Arithmetic mean")

## define total codes
table$total_codes(
  `C-A11-0` = "A11-1",
  `C-STAATS-0` = "STAATS-9",
  `C-VEBDL-0` = "VEBDL-10",
  `C-BESCHV-0` = "BESCHV-1"
)

## alternatively, use partial matching to define totals
table$total_codes(
  Sex = "Sum total",
  Citizenship = "Total",
  Region = "Total",
  `Form of employment` = "Total"
)

# filter for totals in `Region (NUTS2)` and `Form of employment`. Drop totals
# in `Sex` and `Citizenship`.
table$tabulate("Sex", "Citizenship")

## switch language
table$language <- "de"

## `...` matches for codes and labels
table$tabulate("C-A11-0", "Staats", "2. Quartil (Median)")

## Keep totals in the output by removing total codes
table$tabulate("C-A11-0")      # -> 2 rows: "male" "female"
table$total_codes(`C-A11-0` = NA)
table$tabulate("C-A11-0")      # -> 3 rows: "total", "male", "female"

## table$tabulate(...) is an alias for sc_tabulate(table, ...)
sc_tabulate(table, "C-A11-0")

######################## 'STATcube' REST API ################################


table_tourism <- sc_table(sc_example("accomodation.json"), "de")

table_tourism$tabulate()
table_tourism$tabulate("Saison/Tourismusmonat")
table_tourism$tabulate("Saison/Tourismusmonat", "Ankünfte")
table_tourism$tabulate("Ankünfte")


[Package STATcubeR version 1.0.0 Index]