Learn R Programming

RMassBank (version 2.0.0)

add.formula: Calculations on molecular formulas

Description

Add, subtract, and multiply molecular formulas.

Usage

add.formula(f1, f2, as.formula = TRUE, as.list = FALSE) multiply.formula(f1, n, as.formula = TRUE, as.list = FALSE)

Arguments

f1, f2
Molecular formulas (in list form or in text form) to calculate with.
as.formula
Return the result as a text formula (e.g. "C6H12O6"). This is the default
as.list
Return the result in list format (e.g. list(C=6, H=12, O=6)).
n
Multiplier (positive or negative, integer or non-integer.)

Value

The resulting formula, as specified above.

Details

Note that the results are not checked for plausibility at any stage, nor reordered.

See Also

formulastring.to.list, is.valid.formula, order.formula

Examples

Run this code

##

add.formula("C6H12O6", "C3H3")
add.formula("C6H12O6", "C-3H-3")
add.formula("C6H12O6", multiply.formula("C3H3", -1))

Run the code above in your browser using DataLab