Add two pounds, shillings, and pence values that are in the form of lsd objects, numeric vectors, or lists of numeric vectors. If one of lsd1 and lsd2 is a list and the other is a vector, the vector will be recycled.

deb_add(lsd1, lsd2, bases = c(20, 12), round = 5)

Arguments

lsd1, lsd2

lsd values. Objects of class lsd or objects that can be coerced to class lsd: numeric vectors of length 3 or lists of such vectors. If lsd1 and lsd2 are both lists, they must be the same length, or one must be of length 1.

bases

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 lsd1 and/or lsd2 is of class lsd, the bases attribute will be used in the place of this argument. If the bases attributes of lsd1 and lsd2 are different, an error will be thrown.

round

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

See deb_sum() to get the sum of multiple numeric vectors and/or lists of numeric vectors, reducing the inputs to a single numeric vector.

See also

Other lsd arithmetic functions: deb_divide, deb_multiply, deb_subtract, deb_sum

Examples

# Add pounds, shillings, and pence deb_add(lsd1 = c(56, 8, 5), lsd2 = c(19, 5, 7))
#> l s d #> [1] 75 14 0
# Add lsd values that have alternative bases deb_add(lsd1 = c(56, 8, 5), lsd2 = c(19, 5, 7), bases = c(20, 16))
#> l s d #> [1] 75 13 12
# If one of the values is of class lsd the bases attribute will be used lsd1 <- deb_as_lsd(lsd = c(56, 8, 5), bases = c(20, 16)) deb_add(lsd1 = lsd1, lsd2 = c(19, 5, 7))
#> l s d #> [1] 75 13 12
# If lsd1 and lsd2 have different bases, the function will throw an error lsd2 <- deb_as_lsd(lsd = c(19, 5, 7), bases = c(20, 12))
# NOT RUN { deb_add(lsd1 = lsd1, lsd2 = lsd2) # }
# deb_add with two vectors is equivalent to using deb_sum deb_sum(c(56, 8, 5), c(19, 5, 7))
#> l s d #> [1] 75 14 0
# deb_add is useful when one or both of lsd1 and lsd2 # are lists of numerical vectors # With two lists of the same length each vector in lsd1 # will be added to the corresponding vector in lsd2. deb_add(lsd1 = list(c(56, 8, 5), c(27, 12, 4)), lsd2 = list(c(19, 5, 7), c(6, 3, 2)))
#> l s d #> [1] 75 14 0 #> [2] 33 15 6
# As opposed to using deb_normalize, which will not work
# NOT RUN { deb_normalize(list(c(56, 8, 5), c(27, 12, 4)) + list(c(19, 5, 7), c(6, 3, 2))) # }
# If lsd1 and lsd2 are lists of different lengths, # one must be of length one, which is the same as # if the shorter list was a vector. deb_add(lsd1 = list(c(56, 8, 5), c(27, 12, 4), c(78, 14, 11)), lsd2 = list(c(6, 18, 10)))
#> l s d #> [1] 63 7 3 #> [2] 34 11 2 #> [3] 85 13 9