Units {Mensuration} | R Documentation |
This routine will do unit conversions based on the GNU “Units” command (see References section). Any conversions that are legal there will work here.
Units(x = c(3, 5), from = c("m"), to = "ft")
x |
a vector of quantities in the |
from |
a vector of units that apply to |
to |
a vector of units that we want |
See examples below, just make sure things are compatible with
the GNU “Units” command. If any unit conversions are illegal,
it will throw an error. It does not do much checking beyond this, so
it will take whatever is given to it. This works flawlessly on Linux,
and may be installed with dnf
(Red Hat/Fedora and derivatives)
or the system package manager. It requires downloading and installing
GNU “Units” on other operating systems (see below).
A data frame with the first column the actual command that can be used in
system
, the second column contains the original quantities x
to be
converted, and the third column holds the conversions asked for.
The routine uses a capital “U” because it was conflicting
with the units
command in R's base package.
JHG
Please see http://www.gnu.org/software/units/units.html
information about units
and its use (and installation on other systems).
# # okay to run if you have GNU units installed... # ## Not run: Units(1,'m','ft') #simple conversion factor Units(c(25,50),'m^2/hectare','ft^2/acre') #basal area quantities Units(c(250,500),'ft^3/acre','m^3/hectare') #volume quantities Units(c(250,1,1),c('ft^3/acre','acre','hectare'),c('m^3/hectare','hectare','acre')) #mixture ## End(Not run)