Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

r - Formatting numbers with hugrex function in huxtable

Function huxreg in the huxtable package automatically recognises numbers and formats them as predefined in the number_format = "%.3f" option. I would like to report confidence intervals in my report and use the CI95: prefix. Unfortunately, the numerical part of the prefix is automatically formatted and the prefix looks like CI95.000.

Let's consider following example:

library(huxtable)
data <- data.frame(y = rnorm(10), x=rnorm(10))
fit <- lm(y ~ x, data)

huxreg(fit,
     ci_level = 0.95,
     error_pos = "below",
     error_format = "CI95: ({conf.low}, {conf.high})" )

enter image description here

Is there any way to get the CI95 as intended? I have tried numeric to character conversions with no success. Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

While not optimal, you could perhaps add , number_format = c("%.3f", "%.3g", "%.3f", "%.3g") to your huxreg call to specifically affect the formatting of the CI95 rows of your table (or save the output as an object and then modify the attribute elements that define the formatting of those lines, e.g. do attr(res, "number_format")[[13]] <- "%.3g", etc.). Other than that I could only think of somehow modifying the underlying glue transformer that transforms the entire string and leaves all numeric elements with the same formatting.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...