Normalize pounds, shillings, and pence to standard unit bases.

deb_normalize(lsd, bases = c(20, 12), round = 5)

Arguments

lsd An lsd value. An object of class lsd or an object that can be coerced to class lsd: a numeric vector of length 3 or a list of such vectors. Numeric vector of length 2 used to specify the bases for the shillings or s and pence or d units. Default is c(20, 12), which conforms to the most widely used system of 1 pound = 20 shillings and 1 shilling = 12 pence. If lsd is of class lsd, the bases attribute will be used in the place of this argument. Round pence unit to specified number of decimal places. Default is 5. Set to 0 to return pence as whole number.

Value

Returns an object of class lsd with a bases attribute.

Details

deb_normalize() uses the nomenclature of l, s, and d to represent pounds, shillings, and pence units. The abbreviations derive from the Latin terms libra, solidus, and denarius. In the 8th century a solidus came to represent 12 denarii coins, and 240 denarii were made from one libra or pound of silver. The custom of counting coins in dozens (solidi) and scores of dozens (librae) spread throughout the Carolingian Empire and became engrained in much of Europe. However, other bases for the solidus and denarius units were also in use. The bases attribute makes it possible to specify alternative bases for the solidus and denarius units.

Examples

# Use to normalize the values of pounds, shillings, and pence
deb_normalize(lsd = c(5, 55, 42))#>     l  s d
#> [1] 7 18 6
# Normalize values with alternative bases for solidus and denarius units
# For instance, the Dutch system of guilders, stuivers, and penningen
deb_normalize(lsd = c(5, 55, 42), bases = c(20, 16))#>     l  s  d
#> [1] 7 17 10
# Normalizing an object of class lsd will use the bases attribute
lsd <- deb_as_lsd(lsd = c(5, 55, 42), bases = c(20, 16))
deb_normalize(lsd = lsd)#>     l  s  d
#> [1] 7 17 10
# Normalize multiple values with a list of numeric vectors
lsd_list <- list(c(4, 34, 89), c(-9, -75, -19), c(15.85, 36.15, 56))
deb_normalize(lsd = lsd_list)#>       l   s    d
#> [1]   6   1  5.0
#> [2] -12 -16 -7.0
#> [3]  17  17  9.8
# Or an lsd object with alternative bases
lsd_list2 <- deb_as_lsd(lsd = lsd_list, bases = c(20, 16))
deb_normalize(lsd = lsd_list2)#>       l   s    d
#> [1]   5  19  9.0
#> [2] -12 -16 -3.0
#> [3]  17  16 10.4
# It is possible to perform arithmetic within the function
deb_normalize(lsd = c(5 + 6, 20 + 18, 8 + 11))#>      l  s d
#> [1] 12 19 7
# deb_normalize can deal with negative values
deb_normalize(lsd = c(-5, -25, -22))#>      l  s   d
#> [1] -6 -6 -10
# Or a mixture of positive and negative values
# if that occurs for some reason
deb_normalize(lsd = c(5, -25, 22))#>     l  s  d
#> [1] 3 16 10
# Can also properly normalize decimalized pounds and shillings
deb_normalize(lsd = c(8.7, 33.65, 15))#>      l s    d
#> [1] 10 8 10.8
# Round argument can be used to round pence unit to
# specific decimal place and properly normalize value
# Compare with default of round = 5 to round = 0
deb_normalize(lsd = c(5.7, 44.742, 15), round = 5)#>     l  s      d
#> [1] 7 19 11.904deb_normalize(lsd = c(5.7, 44.742, 15), round = 0)#>     l s d
#> [1] 8 0 0
# It is possible to do arithmetic within the lsd argument
# if inputs are all vectors.
deb_normalize(lsd = c(56, 8, 5) + c(19, 5, 7))#>      l  s d
#> [1] 75 14 0deb_normalize(lsd = c(56, 8, 5) - c(19, 5, 7))#>      l s  d
#> [1] 37 2 10deb_normalize(lsd = c(56, 8, 5) * 3)#>       l s d
#> [1] 169 5 3deb_normalize(lsd = c(56, 8, 5) / 3)#>      l  s       d
#> [1] 18 16 1.66667
# This will not work if one of the objects is a list
# Use arithmetic functions for this
# NOT RUN {
deb_normalize(list(c(56, 8, 5), c(27, 12, 4)) + list(c(19, 5, 7), c(6, 3, 2)))
deb_normalize(list(c(56, 8, 5), c(27, 12, 4)) - c(19, 5, 7))
deb_normalize(list(c(56, 8, 5), c(27, 12, 4)) * 3)
deb_normalize(list(c(56, 8, 5), c(27, 12, 4)) / 3)
# }