Skip to contents

Convert the unit attribute of deb_decimal vectors.

Usage

deb_convert_unit(x, to = c("l", "s", "d", "f"))

Arguments

x

A vector of class deb_decimal.

to

A character vector of length one indicating the unit to be converted to. Choice of "l" (libra, the default), "s" (solidus), "d" (denarius), or "f" (farthing).

Value

A deb_decimal vector with a converted unit attribute.

Details

deb_convert_unit() converts the unit of a deb_decimal vector to either "l", "s", "d", or optionally "f" if the vector has tetrapartite bases. This changes the representation of the vector, but the value remains equivalent.

Examples


x <- deb_decimal(c(8.825, 15.125, 3.65))
y <- deb_decimal(c(56.45, 106.525, 200.4), unit = "s")
z <- deb_decimal(c(8472, 14520,  3504),
                 unit = "f",
                 bases = c(20, 12, 4))

deb_convert_unit(x, to = "s")
#> <deb_decimal[3]>
#> [1] 176.5 302.5  73.0
#> # Unit: solidus
#> # Bases: 20s 12d
deb_convert_unit(x, to = "d")
#> <deb_decimal[3]>
#> [1] 2118 3630  876
#> # Unit: denarius
#> # Bases: 20s 12d
deb_convert_unit(y, to = "l")
#> <deb_decimal[3]>
#> [1]  2.82250  5.32625 10.02000
#> # Unit: libra
#> # Bases: 20s 12d
deb_convert_unit(y, to = "d")
#> <deb_decimal[3]>
#> [1]  677.4 1278.3 2404.8
#> # Unit: denarius
#> # Bases: 20s 12d
deb_convert_unit(z, to = "l")
#> <deb_decimal[3]>
#> [1]  8.825 15.125  3.650
#> # Unit: libra
#> # Bases: 20s 12d 4f
deb_convert_unit(z, to = "s")
#> <deb_decimal[3]>
#> [1] 176.5 302.5  73.0
#> # Unit: solidus
#> # Bases: 20s 12d 4f