Sum multiple pounds, shillings, and pence values, reducing the values to a single pounds, shillings, and pence value in the form of an lsd object.

deb_sum(..., bases = c(20, 12), round = 5, na.rm = FALSE)

Arguments

...

Objects of class lsd or objects that can be coerced to class lsd: numeric vectors of length 3 or lists of such vectors. All lsd objects must have the same bases.

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 any of the lsd values are lsd objects, the bases attribute will be used in the place of this argument. All lsd objects must have the same bases.

round

Round pence unit to specified number of decimal places. Default is 5. Set to 0 to return pence as whole number.

na.rm

Logical. Passed on to na.rm argument in sum(). Whether missing values (NA) should be removed. Default is FALSE.

Value

Returns an lsd object with a bases attribute.

Details

See deb_add() to add an lsd value or list of lsd values to the elements of a list of lsd values.

See also

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

Examples

# Sum of multiple lsd values deb_sum(c(12, 7, 9), c(5, 8, 11), c(3, 18, 5))
#> l s d #> [1] 21 15 1
# Sum of multiple lsd values with alternative bases deb_sum(c(12, 7, 9), c(5, 8, 11), c(3, 18, 5), bases = c(20, 16))
#> l s d #> [1] 21 14 9
# If one value is an lsd object, the bases attribute will be used lsd <- deb_as_lsd(lsd = c(12, 7, 9), bases = c(20, 16)) deb_sum(lsd, c(5, 8, 11), c(3, 18, 5))
#> l s d #> [1] 21 14 9
# Sum of a lsd object of length > 1 lsd_list <- deb_as_lsd(lsd = list(c(12, 7, 9), c(5, 8, 11), c(3, 18, 5))) deb_sum(lsd_list)
#> l s d #> [1] 21 15 1
# Sum of a mixture of lsd vectors and list of lsd vectors deb_sum(lsd_list, c(8, 4, 9), c(6, 19, 10))
#> l s d #> [1] 36 19 8
# Cannot find sum of lsd objects that have different bases
# NOT RUN { deb_sum(lsd, lsd_list) # }