View source: R/cbs4_add_date_column.R
cbs4_add_date_column | R Documentation |
Add extra date columns to data set, for the creation of time series or graphics.
cbs4_add_date_column(data, date_type = c("Date", "numeric"), ...)
data |
|
date_type |
Type of date column: "Date", "numeric". See details. |
... |
future use. |
Time periods in data of CBS are coded: yyyyXXww (e.g. 2018JJ00, 2018MM10, 2018KW02),
which contains year (yyyy), type (XX) and index (ww). cbs4_add_date_column
converts
these codes into a Date()
or numeric
.
"Date"
will create a date that signifies the start of the period:
"2018JJ00" will turn into "2018-01-01"
"2018KW02" will turn into "2018-04-01"
"numeric"
creates a fractional
number which signs the "middle" of the period. e.g. 2018JJ00 -> 2018.5 and
2018KW01 -> 2018.167. This is for the following reasons: otherwise 2018.0 could mean
2018, 2018 Q1 or 2018 Jan, and furthermore 2018.75 is a bit strange for 2018 Q4.
If all codes in the dataset have frequency "Y" the numeric output will be integer
.
The <period_freq>
column indicates the period type / frequency:
Y
: year
Q
: quarter
M
: month
W
: week
D
: day
original dataset with two added columns: <period>_Date
and
<period>_freq
. See details.
cbs4_get_metadata()
Other add metadata columns:
cbs4_add_label_columns()
,
cbs4_add_unit_column()
if (interactive()){ # works on observations... obs <- cbs4_get_observations( id = "80784ned" # table id , Perioden = "2019JJ00" # Year 2019 , Geslacht = "1100" # code for total gender , RegioS = "NL01" # code for region NL , Measure = "M003371_2" ) # add a Periods_Date column obs_d <- cbs4_add_date_column(obs) obs_d # add a Periods_numeric column obs_d <- cbs4_add_date_column(obs, date_type = "numeric") obs_d # works on data d <- cbs4_get_data( id = "80784ned" # table id , Perioden = "2019JJ00" # Year 2019 , Geslacht = "1100" # code for total gender , RegioS = "NL01" # code for region NL , Measure = "M003371_2" ) cbs4_add_date_column(d) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.