Computes the sum of digits for whole-numbered inputs. Negative values are handled by taking the absolute value.
Details
The function accepts integer vectors as well as doubles holding whole
numbers (e.g. 124 and 124L are both valid). Fractional
values raise an error. Missing values (NA) are propagated.
See also
Other number.theory:
GCD-LCM,
divisors(),
factorize(),
fibonacci(),
isOdd(),
isPrime(),
primes()
Examples
digitSum(124)
#> [1] 7
digitSum(c(10L, 99L, -1234L))
#> [1] 1 18 10
