diffScenarios | R Documentation |
This function takes a single query for two scenarios and computes the difference between them for all years in the scenario. Entries that exist in one of the scenarios but not the other will be assigned a NA value in the output.
diffScenarios(
data,
scenarios = NULL,
keycols = "region",
data2 = NULL,
aggfun = sum
)
data |
The input query data. The expected format is described below. |
scenarios |
The scenarios to difference from the input data. Order is significant; it determines which scenario will be subtracted, and which will be subtracted from. |
keycols |
Columns by which to aggregate the data. The default is to
aggregate by region. If |
data2 |
If the two scenarios are in separate data frames, pass the
scenario to be subtracted in this argument. In this case, the
|
aggfun |
Function to use in aggregation. The default is |
The input data should consist of a data frame with a scenario
column,
one or more id columns (region
, sector
, etc.), and a series of
columns containing the data. We assume that any column with numeric data in
it is a data column. Any columns other than the key columns and data columns
will be dropped as part of the aggregation.
By default, both scenarios are expected to be contained in a single data
frame, distinguished by the scenario
column. There can be more than
two scenarios in the data frame; the scenarios
argument will determine
which ones actually get used. The scenarios
argument also determines
the order of the differencing (i.e., scenario1 - scenario2
vs. scenario2 - scenario1
.
By default the data is aggregated by region before differencing, but this
behavior can be changed with the keycols
argument. You can specify
one or more key columns to change the aggregation variable, or you can set
keycols=NULL
to retain all of the input columns and not do any
aggregation. Aggregation is by summing, by default, but an alternative
aggregation function can be specified in the aggfun
argument.
If you happen to have the data for the two scenarios in separate data frames,
you can pass the second data frame in the data2
argument. In this
case, the scenarios
argument will be ignored, and the difference will
be computed as data - data2
.
Data frame with the difference between the two scenarios. The key
columns and year columns will be retained; all other columns (including the
scenario
column will be dropped.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.