ud.convert | R Documentation |
This function takes the numeric argument x
,
quantified in units u1
and converts it to be of units u2
.
ud.convert(x, u1, u2)
x |
Some argument which is convertible to a numeric type by |
u1 |
A character string which is parseable into a udunits compatible unit. |
u2 |
Another character string which is also parseable into a udunits compatible unit and for which there exists a defined transformation from the units represented by u1. |
This function uses the udunits function cv_convert_doubles
to
convert the argument from one set of units to another.
Returns a numeric type having converted from one unit to another. The
attributes of the original argument x
(e.g. class, dimensions,
etc.) are preserved and then re-applied to the return value of the
transformation as such:
attributes(rv) <- attributes(x)
If either of unit u1
or u2
is unparseable, or there does
not exist a conversion from one to the other the function raises an error.
James Hiebert hiebert@uvic.ca
Unidata's udunits reference: https://www.unidata.ucar.edu/software/udunits/ API guide for cv_convert_doubles: https://www.unidata.ucar.edu/software/udunits/udunits-2.1.24/udunits2lib.html#index-cv_005fconvert_005fdoubles-39
ud.are.convertible
x <- seq(10) ud.convert(x, "miles", "km") # c(1.609344, 3.218688, 4.828032, ...) x <- c(-40, 0, 100) ud.convert(x, "celsius", "degree_fahrenheit") # c(-40, 32, 212) err <- try(ud.convert(100,"miles", "grams")) # Error err <- try(ud.convert(NA, "not", "parseable")) # Error
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.