Description Usage Arguments See Also Examples
Align numbers for neat vertical printing
1 2 |
x |
numeric or character vector |
lpad, rpad |
character strings used for padding. Repeated to length |
dec |
decimal seperator, or any other character to align by |
min.dec |
pad with zeros to reach a minimum number of decimal points |
rm.dec |
remove zeros at the end of whole numbers |
align_char
, for alignment more aimed at character strings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | x <- c(22100, 100, 1015, 13.018, 0.1, 0.01234)
cat(align_num(x), sep="\n") # Default
cat(format(x, scientific=FALSE), sep="\n")
cat(align_num(x, rpad=" "), sep="\n")
cat(align_num(x, rpad=" ", rm.dec=FALSE), sep="\n")
cat(align_num(x, rpad=" ", min.dec=1), sep="\n")
cat(align_num(x, rpad=" ", min.dec=2), sep="\n")
cat(align_num(x, rpad="\U00b7", min.dec=0), sep="\n")
cat(align_num(x, lpad="' ", rpad=" '", min.dec=0), sep="\n")
cat(align_num(c("1.000.000", "10.000.000", "1.000,85"), dec=","), sep="\n")
# corner cases
x <- c("100.", "1.2", ".1111")
cat(align_num(x, rpad=" ", rm.dec=TRUE), sep="\n")
cat(align_num(round(as.numeric(x)), rpad=" ", rm.dec=TRUE), sep="\n")
# matching on more than one character
# so far not much more advanced than this
# working on align_num2 more suited for character strings
s <- c("cataract", "hematology", "pancreatic")
cat(align_num(s, dec="a", rpad=" "), sep="\n")
cat(align_num(s, dec="at", rpad=" "), sep="\n")
a <- c("Tom and Jerry", "Milo and Stich", "Abbott and Costello")
cat(align_num(a, dec="and", rpad=" "), sep="\n")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.