Created
January 29, 2019 03:57
-
-
Save jcheng5/5a90fd10eb255e978944b319ac850959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_suffix <- function(x, base = 1000, suffixes = c("K", "M", "B", "T")) { | |
if (length(suffixes) == 0) { | |
tibble( | |
scale_by = rep_len(1, length(x)), | |
suffix = rep_len("", length(x)) | |
) | |
} | |
i <- floor(log(abs(x), base = base)) | |
i <- pmin(i, length(suffixes)) | |
tibble( | |
scale_by = base ^ i, | |
suffix = ifelse(i == 0, "", suffixes[pmax(1, i)]) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment