Denominate.data.frame {COINr} | R Documentation |
Denominate data sets by other variables
Description
"Denominates" or "scales" variables 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 'data.frame'
Denominate(
x,
denoms,
denomby,
x_ID = NULL,
denoms_ID = NULL,
f_denom = NULL,
...
)
Arguments
x |
A data frame of data to be denominated. Columns to be denominated must be numeric, but any columns not
specified in |
denoms |
A data frame of denominator data. Columns should be denominator data, with column names corresponding
to entries in |
denomby |
A data frame which specifies which denominators to use for each indicator, and any scaling factors
to apply. Should have columns |
x_ID |
A column name of |
denoms_ID |
A column name of |
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. |
... |
arguments passed to or from other methods. |
Details
A data frame x
is denominated by variables found in another data frame denoms
, according to specifications in
denomby
. denomby
specifies which columns in x
are to be denominated, and by which columns in denoms
, and
any scaling factors to apply to each denomination.
Both x
and denomby
must contain an ID column which matches the rows of x
to denomby
. If not specified, this
is assumed to be uCode
, but can also be specified using the x_ID
and denoms_ID
arguments. All entries in
x[[x_ID]]
must be present in denoms[[denoms_ID]]
, although extra rows are allowed in denoms
. This is because
the rows of x
are matched to the rows of denoms
using these ID columns, to ensure that units (rows) are correctly
denominated.
By default, columns of x
are divided by columns of denoms
. This can be generalised by setting f_denom
to another
function which takes two numeric vector arguments. I.e. setting denoms = ``*``
will multiply columns of x
and
denoms together.
Value
A data frame of the same size as x
, with any specified columns denominated according to specifications.
See Also
-
WorldDenoms A data set of some common national-level denominators.
Examples
# Get a sample of indicator data (note must be indicators plus a "UnitCode" column)
iData <- ASEM_iData[c("uCode", "Goods", "Flights", "LPI")]
# Also get some denominator data
denoms <- ASEM_iData[c("uCode", "GDP", "Population")]
# specify how to denominate
denomby <- data.frame(iCode = c("Goods", "Flights"),
Denominator = c("GDP", "Population"),
ScaleFactor = c(1, 1000))
# Denominate one by the other
iData_den <- Denominate(iData, denoms, denomby)