R: Get a factor to convert concentrations.

calc_factor_conc {bioset} | R Documentation

## Get a factor to convert concentrations.

### Description

Calculate a factor to convert concentration "A" into concentration "B".

### Usage

    calc_factor_conc(from, to, molar_mass = 0, density_solute = 0,
      density_solution = 0)

### Arguments

`from` | A string containing the units of concentration A.
`to` | A string containing the units of concentration B.
`molar_mass` | The molar mass of the solute (g / mol).
`density_solute` | The density of the solute (g / l).
`density_solution` | The density of the solution (g / l), not the solvent!

### Details

The following concentrations can be converted:

mass / volume: ".g / .l", ".g / .m^3", "% w / v"

molar / volume: ".M", ".mol / .l", ".mol / .m^3"

volume / volume: ".l/.l", ".l / m^3", ".m^3/.m^3", ".m^3 / .l", "% v / v", "v / v"

mass / mass: ".g / .g", "w / w", "% w / w"

Where "." symbolizes a metric prefix (see `calc_factor_prefix()`) :

For g, l, mol and M: d (deci), c (centi), m (milli), µ (micro), n (nano), p (pico) and f (femto).

For g you might use k (kilo) as well.

For m^3 (cubic metres) you may only use: d (deci), c (centi) and m (milli).

Note: % w / v is (incorrectly) taken as a short hand for 0.1 g / l.

### Value

The factor to convert A into B.

### See Also

Other conversion functions: `calc_factor_prefix`, `convert_conc`, `convert_prefix`

### Examples

    library("dplyr")

    # generate test data
    data <- tibble(
      sample = c("A", "B", "C"),
      conc = c(4.5, 2.3, 5.1),       # concentration in g  / l
    )

    fctr_ng_ml <- calc_factor_conc(from = "g/l", to = "ng/ml")
    # give molar mass in g / mol
    fctr_mol_l <- calc_factor_conc(from = "g/l", to = "M", molar_mass = 78.971)
    # give densities in g / l
    fctr_pc <- calc_factor_conc(from = "g/l", to = "%v/v", density_solute = 4810)

    data %>%
      mutate(
        conc_ng_ml = conc * fctr_ng_ml,
        conc_mol_l = conc * fctr_mol_l,
        conc_pc = conc * fctr_pc
    )

    # throws an error
    ## Not run:
    # will throw an error because molar_mass is missing
    fctr_fail <- calc_factor_conc(from = "g/l", to = "mol/l")

    ## End(Not run)

[Package bioset version 0.2.2 Index]