Math.units {units} | R Documentation |
Mathematical operations for units objects
Description
Mathematical operations for units objects
Usage
## S3 method for class 'units'
Math(x, ...)
Arguments
x |
object of class units |
... |
parameters passed on to the Math functions |
Details
Logarithms receive a special treatment by the underlying udunits2
library. If a natural logarithm is applied to some unit
, the result is
ln(re 1 unit)
, which means natural logarithm referenced to
1 unit
. For base 2 and base 10 logarithms, the output lb(...)
and lg(...)
respectively instead of ln(...)
.
This is particularly important for some units that are typically expressed in
a logarithmic scale (i.e., bels, or, more commonly, decibels),
such as Watts or Volts. For some of these units, the default udunits2
database contains aliases: e.g., BW
(bel-Watts) is an alias of
lg(re 1 W)
; Bm
(bel-milliWatts) is an alias of
lg(re 0.001 W)
; BV
is an alias of lg(re 1 V)
(bel-Volts),
and so on and so forth (see the output of valid_udunits()
for further
reference).
Additionally, the units package defines B
, the bel, by
default (because it is not defined by udunits2) as an alias of
lg(re 1)
, unless a user-provided XML database already contains a
definition of B
, or the define_bel
option is set to FALSE
(see help(units_options)
).
Examples
# roundings, cummulative functions
x <- set_units(sqrt(1:10), m/s)
signif(x, 2)
cumsum(x)
# trigonometry
sin(x) # not meaningful
x <- set_units(sqrt(1:10), rad)
sin(x)
cos(x)
x <- set_units(seq(0, 1, 0.1), 1)
asin(x)
acos(x)
# logarithms
x <- set_units(sqrt(1:10), W)
log(x) # base exp(1)
log(x, base = 3)
log2(x)
log10(x)
set_units(x, dBW) # decibel-watts
set_units(x, dBm) # decibel-milliwatts