denominate: Denominate indicator data sets

Description Usage Arguments Details Value See Also Examples

View source: R/coin_denominate.R

Description

Denominates (divides) indicators by other "denominator" indicators that are either input here or were attached as "Den_*" columns of IndData when assembling the COIN. This function can work either on COINs or on data frames.

Usage

1
2
3
4
5
6
7
8
9
denominate(
  obj,
  dset = NULL,
  specby = NULL,
  denomby = NULL,
  scaledenoms = NULL,
  denominators = NULL,
  out2 = "COIN"
)

Arguments

obj

COIN object or a data frame of indicator data to be denominated. If a data frame, must include a UnitCode column.

dset

The data set to denominate (only if COIN used as input)

specby

Selects the source of the specifications for denomination.

  • If "metadata", uses the denominator column in .$metadata.

  • If "user", takes a character vector of denominator codes (one for each indicator, with NA for indicators that should not be denominated, and in the same order as the indicators).

denomby

Character vector specifying which denominators to use for each indicator. Only used if specby = "user". For indicators with no denomination, set elements to NA. Elements must be column names of denominators.

scaledenoms

This allows the possibility to scale denominators if needed. 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. This should be a named list of the form e.g. list(Den_GDP = 1e-9), where the name is the denominator to be scaled, and the entry is a factor to multiply the denominator values by. In the example, this would multiply GDP values by 1e-9, which (if the original values are in dollars) would scale them to billions of dollars. The list can include more than one entry, corresponding to any denominators that are present.

denominators

A data frame of denominator data. Columns should be denominator data, with column names corresponding to entries in denomby. This must also include a UnitCode column to match units (ordering is unimportant, this is done inside the function). Ensure that the unit codes correspond to the unit codes in the indicator data.

out2

Where to output the results. If "COIN" (default for COIN input), appends to updated COIN, otherwise if "df" outputs to data frame.

Details

Typically, the aim here is to convert extensive (size-related) variables into intensive variables(comparable between units of different sizes). There is also the option scaledenoms to scale denominators to avoid very small or very large numbers resulting.

This function expects that denominators$UnitCode contains all unit codes found in the data frame to be denominated. Unused unit codes (rows) in denominators will be ignored. Note that some national-level denominator data is available inside COINr at COINr::WorldDenoms.

See online documentation for further details and examples.

Value

If out2 = COIN and obj is a COIN, returns an updated COIN object, with new dataset .$Data$Denominated of denominated indicators. Otherwise returns a data frame of denominated indicator data.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# assemble ASEM COIN
ASEM <- assemble(IndData = ASEMIndData, IndMeta = ASEMIndMeta, AggMeta = ASEMAggMeta)
# denominate using specs present on assembly
ASEM <- denominate(ASEM, dset = "Raw")

# OR, use function on data frame
# Get a sample of indicator data (note must be indicators plus a "UnitCode" column)
IndData <- ASEMIndData[c("UnitCode", "Goods", "Services", "FDI")]
# Also get some denominator data
Denoms <- ASEMIndData[c("UnitCode", "Den_Pop", "Den_GDP")]
# Denominate one by the other
IndDataDenom <- denominate(IndData, denomby = c("Den_GDP", NA, "Den_Pop"), denominators = Denoms)

COINr documentation built on Nov. 30, 2021, 9:06 a.m.