Confirm that an IEA-style data frame conserves energy.
Source:R/energy_balance.R
verify_IEATable_energy_balance.Rd
Energy balances are confirmed (within tol
) for every combination of
grouping variables in .ieatidydata
.
Usage
verify_IEATable_energy_balance(
.ieatidydata,
ledger.side = "Ledger.side",
energy = "E.dot",
supply = "Supply",
consumption = "Consumption",
err = ".err",
tol = 1e-06
)
Arguments
- .ieatidydata
an IEA-style data frame containing grouping columns (typically
Country
,Year
,Product
, and others), aLedger.side
column, and an energy column (E.ktoe
)..ieatidydata
should be grouped prior to sending to this function.- ledger.side
the name of the column in
.ieatidydata
that contains ledger side information (a string). Default is "Ledger.side
".- energy
the name of the column in
.ieatidydata
that contains energy data (a string). Default is "E.ktoe
".- supply
the identifier for supply data in the
ledger.side
column (a string). Default is "Supply
".- consumption
the identifier for consumption data in the
ledger.side
column (a string). Default is "Consumption
".- err
the name of the error column in the output. Default is "
.err
".- tol
the maximum amount by which Supply and Consumption can be out of balance
Value
a data frame containing with grouping variables and
an additional column whose name is the value of err
.
The err
column should be 0.
Details
Be sure to group .ieatidydata
prior to calling this function,
as shown in the example.
If energy is in balance for every group, a data frame with additional column err
is returned.
If energy balance is not observed for one or more of the groups,
a warning is emitted.
Examples
library(dplyr)
UKEnergy2000tidy %>%
filter(Last.stage %in% c("Final", "Useful")) %>%
group_by(Country, Year, Energy.type, Last.stage) %>%
verify_IEATable_energy_balance(energy = "E.dot")
#> # A tibble: 2 × 7
#> # Groups: Country, Year, Energy.type [1]
#> Country Year Energy.type Last.stage ESupply EConsumption .err
#> <chr> <dbl> <chr> <chr> <dbl> <dbl> <dbl>
#> 1 GBR 2000 E Final 71750 71750 0
#> 2 GBR 2000 E Useful 25915. 25915. 0