Calculates the percentage mass of an element (or compound) in a compound

percent_mass(compound, element)

Arguments

compound

the chemical formula of the full compound

element

the chemical formula of the element or compound of interest

Value

the percentage mass of the element or compound of interest

Examples


percent_mass("H2O", "O") ## returns 88.79
#> [1] "The percentage mass of O in H2O is: 88.819 %"
#> [1] 88.819
percent_mass("H2O", "H") ## returns 11.19
#> [1] "The percentage mass of H in H2O is: 5.59 %"
#> [1] 5.59
percent_mass("NaOH", "OH") ## returns 42.52
#> [1] "The percentage mass of OH in NaOH is: 42.519 %"
#> [1] 42.519