"Denominates" or "scales" indicators by other variables. Typically this is done by dividing extensive variables such as GDP by a scaling variable such as population, to give an intensive variable (GDP per capita).
Usage
# S3 method for class 'coin'
Denominate(
x,
dset,
denoms = NULL,
denomby = NULL,
denoms_ID = NULL,
f_denom = NULL,
write_to = NULL,
out2 = "coin",
...
)Arguments
- x
A coin class object
- dset
The name of the data set to apply the function to, which should be accessible in
.$Data.- denoms
An optional data frame of denominator data. Columns should be denominator data, with column names corresponding to entries in
denomby. This must also include an ID column identified bydenoms_IDto match rows. Ifdenomsis not specified, will extract any potential denominator columns that were attached toiDatawhen callingnew_coin().- denomby
Optional data frame which specifies which denominators to use for each indicator, and any scaling factors to apply. Should have columns
iCode,Denominator,ScaleFactor.iCodespecifies an indicator code found indset,Denominatorspecifies a column name fromdenomsto use to denominate the corresponding column fromx.ScaleFactorallows the possibility to scale denominators if needed, and specifies a factor to multiply the resulting values by. For example, if GDP is a denominator and is measured in dollars, dividing will create very small numbers (order 1e-10 and smaller) which could cause problems with numerical precision. Ifdenombyis not specified, specifications will be taken from the "Denominator" column iniMeta, if it exists.- denoms_ID
An ID column for matching
denomswith the data to be denominated. This column should containuMetacodes to match with the data set extracted from the coin.- f_denom
A function which takes two numeric vector arguments and is used to perform the denomination for each column. By default, this is division, i.e.
x[[col]]/denoms[[col]]for given columns, but any function can be passed that takes two numeric vectors as inputs and returns a single numeric vector. See details.- write_to
If specified, writes the aggregated data to
.$Data[[write_to]]. Defaultwrite_to = "Denominated".- out2
Either
"coin"(default) to return updated coin or"df"to output the aggregated data set.- ...
arguments passed to or from other methods
Details
This function denominates a data set dset inside the coin. By default, denominating variables are taken from
the coin, specifically as variables in iData with Type = "Denominator" in iMeta (input to new_coin()).
Specifications to map denominators to indicators are also taken by default from iMeta$Denominator, if it exists.
These specifications can be overridden using the denoms and denomby arguments. The operator for denomination
can also be changed using the f_denom argument.
See also documentation for Denominate.data.frame() which is called by this method.
Examples
# build example coin
coin <- build_example_coin(up_to = "new_coin", quietly = TRUE)
# denominate (here, we only need to say which dset to use, takes
# specs and denominators from within the coin)
coin <- Denominate(coin, dset = "Raw")
#> Written data set to .$Data$Denominated