convertUnits | R Documentation |
This converts flat data to target units as defined in the dataset. It creates three new columns in your dataset: 1. The converted unit value, 3. the conversion factor used, & 4. a recommended acceptance/rejection based on pairs of input & target units. All original columns are retained.
convertUnits(
x,
input_units,
target_units = "target_unit",
value_var,
conv_val_col = "converted_value"
)
x |
Input dataset. |
value_var |
Column name of x containing result values (in quotes). |
conv_val_col |
Name of new values column for converted values (in quotes). |
input_unit |
Column name of x with units to convert from (in quotes). |
target_unit |
Column name of x with units to convert to (in quotes). |
# Make example data
value=c(abs(rnorm(5,1, 0.1)), rnorm(5, 1000, 100), rnorm(5, 20, 1))
raw_units=c(rep('mg/l',5), rep('ug/L', 5), rep('deg C',5))
preferred_units=c(rep('mg/L', 10), rep('deg C',5))
data=data.frame(value,raw_units,preferred_units)
data
# Unit conversion
conv_data=convertUnits(data, input_units='raw_units', target_units='preferred_units', value_var='value', conv_val_col='converted_value')
conv_data
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.