Skip to contents
loading...

Scientific format for columns in {flextable}

Usage

colformat_sci(
  x,
  i = NULL,
  j = NULL,
  digits = 3,
  scipen = 0,
  lod = NULL,
  lod_str = paste("<", lod),
  fancy = TRUE,
  op = c("·", "×", "*", "x")
)

Arguments

x

a flextable object

i

rows selection

j

columns selection

digits

number of digits to display

scipen

penalty to use to decide if numbers are presented in decimal or scientific notation (generally use 0 or -1)

lod

value indicating the limit of detection, for which we should display something like '< lod_value' instead of the actual value; useful for p values (R often uses 2e-16 in that case), chemical measurements ...

lod_str

the string to use, by default, it is < lod_value.

fancy

use a perfect scientific notation (TRUE) or a simplified one like 1.34e-5 (FALSE).

op

the operator character to use in fancy scientific notation

Value

the flextable object with the selected region formatted as scientific numbers.

Examples

summ <- summary(lm(Volume ~ Girth + Height, data = trees))
tabularise(as.data.frame(summ$coefficients)) |>
  colformat_sci() |>
  colformat_sci(j = 'Pr(>|t|)', lod = 2e-16) |>
  Stb$autofit()

Estimate

Std. Error

t value

Pr(>|t|)

-57.988

8.638

-6.71

2.75·10-07

4.708

0.264

17.82

< 2·10-16

0.339

0.130

2.61

1.45·10-02