Debian Codegraph @

man/Math.units.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/math.R
3 \name{Math.units}
4 \alias{Math.units}
5 \title{Mathematical operations for units objects}
6 \usage{
7 \method{Math}{units}(x, ...)
8 }
9 \arguments{
10 \item{x}{object of class units}
11
12 \item{...}{parameters passed on to the Math functions}
13 }
14 \description{
15 Mathematical operations for units objects
16 }
17 \details{
18 Logarithms receive a special treatment by the underlying \pkg{udunits2}
19 library. If a natural logarithm is applied to some \code{unit}, the result is
20 \code{ln(re 1 unit)}, which means \emph{natural logarithm referenced to
21 \code{1 unit}}. For base 2 and base 10 logarithms, the output \code{lb(...)}
22 and \code{lg(...)} respectively instead of \code{ln(...)}.
23
24 This is particularly important for some units that are typically expressed in
25 a logarithmic scale (i.e., \emph{bels}, or, more commonly, \emph{decibels}),
26 such as Watts or Volts. For some of these units, the default \pkg{udunits2}
27 database contains aliases: e.g., \code{BW} (bel-Watts) is an alias of
28 \code{lg(re 1 W)}; \code{Bm} (bel-milliWatts) is an alias of
29 \code{lg(re 0.001 W)}; \code{BV} is an alias of \code{lg(re 1 V)} (bel-Volts),
30 and so on and so forth (see the output of \code{valid_udunits()} for further
31 reference).
32
33 Additionally, the \pkg{units} package defines \code{B}, the \emph{bel}, by
34 default (because it is not defined by \pkg{udunits2}) as an alias of
35 \code{lg(re 1)}, unless a user-provided XML database already contains a
36 definition of \code{B}, or the \code{define_bel} option is set to \code{FALSE}
37 (see \code{help(units_options)}).
38 }
39 \examples{
40 # roundings, cummulative functions
41 x <- set_units(sqrt(1:10), m/s)
42 signif(x, 2)
43 cumsum(x)
44
45 # trigonometry
46 sin(x) # not meaningful
47 x <- set_units(sqrt(1:10), rad)
48 sin(x)
49 cos(x)
50 x <- set_units(seq(0, 1, 0.1), 1)
51 asin(x)
52 acos(x)
53
54 # logarithms
55 x <- set_units(sqrt(1:10), W)
56 log(x) # base exp(1)
57 log(x, base = 3)
58 log2(x)
59 log10(x)
60 set_units(x, dBW) # decibel-watts
61 set_units(x, dBm) # decibel-milliwatts
62 }