One can apply docxtools::format_engr() to a table to switch from computer notation to engineering notation.
(Source: docxtools)
Applying docxtools::format_engr()
to a df changes all columns to engineering notation.
- How to apply the function only to some columns of a df?
- Is there an equivalent function for mathematical notation?
For the toy example below, the idea would be to get the p_Pa
column in engineering/mathematical notation, while all other columns remain the same.
MWE
Table as desired only missing the p_Pa
column in engineering notation
library(docxtools)
density2 <- density
density2$density <- density2$density*1000
kable(density2, digits = 2)
Apply formatting: "all" columns change to engineering notation
# Apply formatting:
density_engr <- density2 %>%
docxtools::format_engr()
kable(density_engr)
Passing sigdig()
to docxtools::format_engr()
(e.g., sth. like "sigdig = c(0,0,2,3,2,3)") to define how to format which column does not help here.
Engineering notation is still applied to ALL columns, only with differing numbers of digits.
The idea is to include the df as kableExtra
table in an R markdown
report compiled with knitr
both to PDF and HTML.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…