knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

digroot

Travis-CI Build Status

The goal of digroot is to calculate digital roots. A digital root is a single digit that is obtained through a recursive sum of digits. This coincides with taking the remainder modulo nine, except for integers which are divisible by nine.

This package was inspired by a Tweet from Thomas Morrill

For example, the digital root of 77 is 5:

7 + 7
1 + 4

The digroot package automates this with the dig_root() function:

digroot::dig_root(77)

These examples demonstrate the digital root's relationship to modular arithmetic:

digroot::dig_root(77)
77 %% 9
digroot::dig_root(729)
729 %% 9
digroot::dig_root(0)
0 %% 9

It's also vectorized, which means that you can get the multiplication table like so:

print(mult <- outer(1:9, 1:9))
matrix(digroot::dig_root(mult), ncol = 9, nrow = 9)

It can also work on really large numbers:

set.seed(2018-08-12)
print(bignum <- paste0(sample(1e10, 100), collapse = ""))
digroot::dig_root(bignum)

For reference, that number is r paste0(substr(bignum, 1, 1), ".", substr(bignum, 2, 3), "e", nchar(bignum) - 1)

You can find the immediate digital sum of a number by using the dig_sum() function:

print(s   <- digroot::dig_sum(bignum))
print(ss  <- digroot::dig_sum(s))
print(sss <- digroot::dig_sum(ss))

Installation

You can install digroot from github with:

# install.packages("remotes")
remotes::install_github("zkamvar/digroot")


zkamvar/digroot documentation built on May 30, 2019, 6:15 p.m.