Description Usage Arguments Details Value Examples
dem.add
is a generic function. It is intended to by applied to the
dem
object and constructs new variables based on existing ones. The
new variables are added as columns to dem and the labels to the variable
values are added to id$lab
.
1 |
x |
A data.tabel, typically |
what |
A length one character vector. What set of variabels? Corrently
available are: |
id. |
The |
breaks |
An optional numeric vector, sepcifying the age breaks to split
age into ageclasses. Default are the 7-folded ageclasses used to weight the
TV-panel: |
To allow the construction of new variabels based on other variabels, these
other variabels have to be present in the x
(usually dem
). This
means they have to be imported in the first place, e.g.:
setup(..., dem.var = c('v1','v2'))
. How do we know which variables are
needed? There is a parameter need
in each subfunction where the needed
variabels are listed. So, to add rims first ask what variabels are needed
and the import the data accordingly, see examples.
Careful with 'gm'
and 'zone'
. These read the corresponding CSV
file in ../data/meta/.
x
, the input data.table (usually dem
) is changed in
place. The new variabels are added as new columns to x
and the
corresponding variable values and labels are added to id$lab
.
1 2 3 4 5 6 7 8 9 10 11 12 | library(tv)
dem.var <- eval(formals(tv:::dem.add.rim)$need)
setup('2018-01-01', 3, dem.var = dem.var, import = TRUE, view = FALSE, prg = FALSE)
dem[] # dem contains additional variables specified in dem.var
dem.add(dem, 'rim') # construct new variables 'rim' (weighting rims).
dem[] # The new variables are added to dem
id$lab$rim_agesex # And theis labels are added to id$lab
# dem.add.calendar only needs 'day' which is always present:
setup('2018-01-01', 3, import = TRUE, view = FALSE, prg = FALSE, dem.uni = FALSE)
dem.add(dem, 'calendar')
id$lab$month
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.