Flextable: change cell value if it meets a condition and formatting

Viewed 217

I have a dataset (called example) like the following one.

mic <- rep(c("One", "Two", "Tree", "Four"), each = 3)  
pap <- rep(c("1", "2", "3", "4"), each = 3)  
ref <- rep(c("Trial 1", "Trial 2", "Trial 3", "Trial 4"), each = 3)  
prob <- c(rep(NA,4), "Nogood", NA, "Bad", "Nogood", "Norel", NA, "Bad", "Nogood")  
example <- data.frame(Micro = mic, Paper = pap, Reference = ref, Problem = prob)  
example

Example

I would like to merge cells vertically when consecutive cells have identical values so I use flextable merge_v() function.

ft_example <- example %>%
flextable() %>%
merge_v(j = ~ Micro + Paper + Reference + Problem) %>%
theme_vanilla()
ft_example

I obtain the following table when knitting in Word: Table obtained

Is there a way to:

  1. Insert a posteriori the value "None identified" in the empty cells in the "Problem" field that are merged together; and
  2. Remove the inappropriate horizontal lines in the "Problem" field when there is one (or more) not empty cells and some empty cells so that there is one horizontal line clearly separating each combination of Micro, Paper, Reference and horizontal lines separating only non empty cells in the Problem field?

You can see the desired result here below: Table desired

0 Answers
Related