View source: R/calc_addVariable.R
calc_addVariable | R Documentation |
Calculate new variables from existing ones, using generic formulas.
calc_addVariable(
data,
...,
units = NA,
na.rm = TRUE,
completeMissing = FALSE,
only.new = FALSE,
variable = variable,
unit = unit,
value = value,
overwrite = TRUE,
skip.missing.rhs = FALSE
)
calc_addVariable_(
data,
.dots,
na.rm = TRUE,
completeMissing = FALSE,
only.new = FALSE,
variable = "variable",
unit = "unit",
value = "value",
overwrite = TRUE,
skip.missing.rhs = FALSE
)
data |
A data frame. |
... |
Formulas to calculate new variables. Either name-value pairs, the path to a .csv file, the content of a .csv file as a string, or a data frame. See details. |
units |
Character vector of units corresponding to new variables. Must
be of length equal to |
na.rm |
If |
completeMissing |
If |
only.new |
If |
variable |
Column name of variables. Defaults to |
unit |
Column name of units. Defaults to |
value |
Column name of values. Defaults to |
overwrite |
If |
skip.missing.rhs |
If |
.dots |
Used to work around non-standard evaluation. See details. If "lhs" = "rhs + calculations - formula", "`lhs 2`" = "lhs / `rhs 2`" where If the new variables should have units, set
list("`lhs 1`" = "`rhs` / `calculation`", "`lhs 2`" = "sin(`rhs 2`)") Units are optionally included with the formulas in a vector like list("`lhs w/ unit`" = c("`rhs 1` + `rhs 2`", "rhs unit") Units do not require quoting. As an alternative, the variable, unit and formula can be specified as a .csv file in this format: variable; unit; formula Carbon Intensity|Cement; Mt CO2/Mt; `Emi|CO2|Cement` / `Production|Cement` or as a single string containing the .csv content (joined by paste(c( "variable; unit; formula", "Consumption|pCap; US$2005/cap; 0.001 * `Consumption`/`Population`"), collapse = '\n') or as a data frame with the same columns: data.frame( variable = 'Consumption|pCap', unit = 'US$2005/cap', formula = '0.001 * `Consumption`/`Population`')
|
A data frame.
Michaja Pehl
data <- inline.data.frame(c(
"model; scenario; region; variable; unit; period; value",
"REMIND; Baseline; USA; GDP|MER; billion US$2005/yr; 2010; 12990",
"REMIND; Baseline; USA; Population; million; 2010; 310.4",
"REMIND; Baseline; USA; PE; EJ/yr; 2010; 91.62",
"REMIND; Baseline; CHN; GDP|MER; billion US$2005/yr; 2020; 8882",
"REMIND; Baseline; CHN; GDP|MER; billion US$2005/yr; 2010; 4119",
"REMIND; Baseline; CHN; Population; million; 2020; 1387",
"REMIND; Baseline; CHN; Population; million; 2010; 1349"))
calc_addVariable(data, "GDPpC" = "`GDP|MER` / Population * 1e3",
"`ln GDPpC`" = "log(GDPpC)",
units = c("US$2005/cap", NA))
calc_addVariable_(
data,
list("`GDPpC`" = c("`GDP|MER` / `Population` * 1e3", "US$/cap"),
"`ln GDPpC`" = "log(`GDPpC`)")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.