sc_data | R Documentation |
This class represents a common interface for datasets returned from the
STATcube REST API and OGD datasets. sc_data
objects are usually created with
od_table()
or sc_table()
.
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.
new()
This class is not exported. Use od_table()
or sc_table()
to initialize objects of class sc_data
.
sc_data$new(data, meta, fields)
data, meta, fields
raw data, metadata and field information.
Do not use directly but initialize objects with sc_table()
or
od_table()
field()
get information about a specific field. The format of
the return value is similar to $meta
. A data.frame
that includes
codes and labels for each level of the field.
sc_data$field(i = 1)
i
specifier for the field. Integer or character. If an integer
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.
x <- od_table("OGD_krebs_ext_KREBS_1") x$field(1) x$field("Sex")
tabulate()
create a tidy dataset. See sc_tabulate()
for details.
sc_data$tabulate(...)
...
arguments that are passed down to sc_tabulate()
x <- od_table("OGD_krebs_ext_KREBS_1") x$tabulate("Reporting year", "Sex")
total_codes()
sc_data$total_codes(...)
...
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.
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")
clone()
The objects of this class are cloneable with this method.
sc_data$clone(deep = FALSE)
deep
Whether to make a deep clone.
## create a new sc_data object via od_table()
x <- od_table("OGD_krebs_ext_KREBS_1")
## show data
x$data
## show metadata
x$meta
## ------------------------------------------------
## Method `sc_data$field`
## ------------------------------------------------
x <- od_table("OGD_krebs_ext_KREBS_1")
x$field(1)
x$field("Sex")
## ------------------------------------------------
## Method `sc_data$tabulate`
## ------------------------------------------------
x <- od_table("OGD_krebs_ext_KREBS_1")
x$tabulate("Reporting year", "Sex")
## ------------------------------------------------
## 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")
earnings$tabulate("Sex", "Form of employment")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.