26.15 Formatting Numbers with XTable
REVIEW As with knitr::kable() we can limit the number of digits displayed to avoid giving an impression of a high level of accuracy or to simplify the presentation. In Table ?? we have removed all decimal points.
# Display a table removing digits from numbers. %>% ds xtable(digits=0 caption="Decimal points." , label="tbldp0") %>% , print(include.rownames=FALSE)
When we have large numbers being displayed it is imperative that we include commas to separate the thousands. Very many mistakes are made misreading numbers that include many digits when commas are not included.
# Take a copy of the dataset so as to change the data. <- ds %>% sample_frac(0.01) dst # Randomly create very large numbers across all but the first variable. -1] <- sample(10000:99999, nrow(dst)) * dst[-1] dst[ # Illustrate the default table display of large numbers. %>% dst xtable(digits=0 caption="Large numbers." , label="tbllrg") %>% , print(include.rownames=FALSE)
Consider the result in Table ??. It is difficult to
distinguish between the thousands and millions. We often find
ourselves having to carefully count the digits to check whether
# A tibble: 1 × 1, MaxTemp,
# Format large numbers using commas as appropriate. %>% dst xtable(digits=0 caption="Large numbers formatted." , label="tbllrgf") %>% , print(include.rownames=FALSE, format.args=list(big.mark=","))
Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0