Reputation: 1546
Is it possible to bold/color estimate values based on tstat.
For ex - bold estimate values if tstat is more than 1.96
This is in continuation of my previous question and I have to use flextable.
library(dplyr)
library(flextable)
attribute <- c("b0", "b1", "b2", "b3", "b4", "b5")
estimate <- round(runif(n = 6, min = 0, max = 5), 2)
tstat <- round(runif(n = 6, min = 0, max = 5), 2)
# tibble
tbl <- tibble(attribute, estimate, tstat) %>%
as_flextable()
Upvotes: 5
Views: 2370
Reputation: 10725
Another solution using flextable row selector:
library(dplyr)
library(flextable)
set.seed(4123)
attribute <- c("b0", "b1", "b2", "b3", "b4", "b5")
estimate <- round(runif(n = 6, min = 0, max = 5), 2)
tstat <- round(runif(n = 6, min = 0, max = 5), 2)
tbl <- tibble(attribute, estimate, tstat)
tbl %>%
flextable() %>%
bold(~ tstat > 1.96,2)
Upvotes: 5
Reputation: 25528
Another solution:
library(dplyr)
library(flextable)
set.seed(4123)
attribute <- c("b0", "b1", "b2", "b3", "b4", "b5")
estimate <- round(runif(n = 6, min = 0, max = 5), 2)
tstat <- round(runif(n = 6, min = 0, max = 5), 2)
tbl <- tibble(attribute, estimate, tstat)
tbl %>%
flextable() %>%
bold(tbl$tstat > 1.96,2)
Upvotes: 2
Reputation: 887971
We could use either ifelse
or case_when
to add the **<value>**
for bold
ing
library(dplyr)
library(flextable)
tbl <- tibble( attribute, estimate, tstat) %>%
mutate(estimate = case_when(tstat > 1.96
~sprintf('**%0.2f**', estimate),
TRUE ~sprintf('%0.2f', estimate))) %>%
as_flextable() %>%
colformat_md()
tbl
-output
Upvotes: 2