Good evening!
I'm currently encountering a challenge with TableOne (and gtsummary) when attempting to create a table with variables of very small orders of magnitude, such as e−8e−8. It seems that TableOne is treating these values as zero due to their minimal size.
Here's a reproducible example:
# library(gtsummary)
library(tableone)
data(iris)
iris$rands <- 1e-9 * runif(n = nrow(iris))
tableone::CreateTableOne(data = iris) |> print()
gives
Overall
n 150
Sepal.Length (mean (SD)) 5.84 (0.83)
Sepal.Width (mean (SD)) 3.06 (0.44)
Petal.Length (mean (SD)) 3.76 (1.77)
Petal.Width (mean (SD)) 1.20 (0.76)
Species (%)
setosa 50 (33.3)
versicolor 50 (33.3)
virginica 50 (33.3)
rands (mean (SD)) 0.00 (0.00)
In this example, I would like to display the actual mean value of the variable, even though it is very small, instead of it being reduced to 0.
Any suggestions on how to handle this issue with TableOne or gtsummary would be greatly appreciated!
Thank you!
Have a look at ?print.TableOne()
:
# library(gtsummary)
library(tableone)
data(iris)
iris$rands <- 1e-9 * runif(n = nrow(iris))
tableone::CreateTableOne(data = iris) |> print(contDigits = 10L)
gives
Overall
n 150
Sepal.Length (mean (SD)) 5.8433333333 (0.8280661280)
Sepal.Width (mean (SD)) 3.0573333333 (0.4358662849)
Petal.Length (mean (SD)) 3.7580000000 (1.7652982333)
Petal.Width (mean (SD)) 1.1993333333 (0.7622376690)
Species (%)
setosa 50 (33.3)
versicolor 50 (33.3)
virginica 50 (33.3)
rands (mean (SD)) 0.0000000005 (0.0000000003)
They are not reduced to zero. Instead they are not displayed due to the default value of contDigits
in print.TableOne()
.