I am trying to use two variables to group data: Country and State_Province. I want to use 'flextable' in R to do this and I also want the two variables to be next to each other in the resulting table separated by a vertical bar.
However using merge_v seems to get rid of the vertical bar and I can't figure out how to add it back in.
Here is a small reproducible example:
library(flextable)
library(dplyr)
big_border = fp_border(color="#2c3a51" , width = 2)
std_border = fp_border(color="#2c3a51" , width = 1)
df <- data.frame(Country = c("US", "US", "US", "Canada", "Canada", "Canada"),
State_Province = c("CA", "CA", "NY", "Quebec", "Quebec", "Alberta"),
data = LETTERS[1:6])
df %>%
flextable() %>%
vline( border = std_border, part = "all" ) %>%
border_outer(part="all", border = big_border ) %>%
merge_v(j = c("Country", "State_Province") )
Instead I have been adding a serperator and removing it before presentations.
myft <- df %>%
flextable(., col_keys = c("Country", "separator", "State_Province", "data"))
myft <- border(myft, j = ~ separator, border = fp_border(width=0), part = "all")
myft <- width(myft, j = ~ separator, width = 0)
myft %>%
merge_v(j = c("Country") ) %>%
vline( border = std_border, part = "all" ) %>%
border_outer(part="all", border = big_border ) %>%
merge_v(j = c("State_Province") )