restore_units | R Documentation |
Operations on tabular data or geodata can result in unit-aware columns being returned to a naive state. This function easily restores them.
restore_units(to, from)
## Default S3 method:
restore_units(to, from)
## S3 method for class 'data.frame'
restore_units(to, from)
to |
numeric vector, tabular data or geodata |
from |
same class as |
same value(s) as from
, but with units set as they were in to
## Not run:
library(dplyr)
library(units)
df <- mutate(mtcars, mpg = as_units(mpg, "mi/gal"))
grouped <- group_by(df, cyl)
summarised <- summarise_at(grouped, vars(mpg), mean)
restore_units(summarised, from = df)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.