convert,character-method | R Documentation |
Convert units
Add units to convert function
## S4 method for signature 'character'
convert(from, to, x = 1, database = "base", ...)
## S4 method for signature 'numeric'
convert(x = 1, from, to, database = "base", ...)
## S4 method for signature 'character,character,numeric'
add_to_convert(
type,
unit,
coef,
alias = "",
SI_prefixes = FALSE,
database = "base",
update = TRUE
)
from |
character of length one with unit name |
to |
character of length one with unit name |
x |
numeric vector with data to convert |
database |
character name of a database with units ( |
... |
currently ignored |
type |
character, type of the unit (one of "Energy", "Power", "Mass", "Time", "Length", "Area", "Pressure", "Density", "Volume", "Flow Rates", "Currency"). |
unit |
character, the name of the new unit to add to the |
coef |
numeric, convert factor to the base unit of this type (see the first column of |
alias |
character vector, alternative name(s) for the same unit. |
SI_prefixes |
logical, can be used with |
numeric vector with converted values
updated convert_data
in the .GlobalEnv
, the values will not update the package data.
convert("MWh", "kWh")
convert("kWh", "MJ")
convert("kWh/kg", "MJ/t", 1e-3)
convert("cents/kWh", "USD/MWh")
convert(1000, "kWh", "MWh")
convert("kWh", "MJ")
convert(1, "kWh/kg", "MJ/t")
convert(5, "cents/kWh", "USD/MWh")
## Not run:
convert_data$base$Currency
add_to_convert("Currency", unit = "JPY", coef = 140)
convert_data$base$Currency
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.