Home > Mobile >  Add double lines between some rows in a dataframe R - Formatting
Add double lines between some rows in a dataframe R - Formatting

Time:08-19

I would like to display a R dataframe with double lines between some rows.

For example to separate groups as in the picture below :

enter image description here

I looked at the functions formattable and kable but I didn't find anything.

CodePudding user response:

I have a solution which works with Rstudio :

library(gt);   library(dplyr)

df = data.frame(Group = c("Tree", "Tree", "Flower", "Flower", "Flower"), Value = sample(c(1 : 20), 5));  

df %>% gt() %>% tab_row_group(group = "", rows = 1:2)

Which gives :

enter image description here

Unfortunately I work with Jupyterlab, and here is an extract of the output I get with it :

enter image description here

CodePudding user response:

So with Jupyterlab It's almost good with this :

library(gt);   library(dplyr)

df = tibble(Group = c("Tree", "Tree", "Flower", "Flower", "Flower"), Value = sample(c(1 : 20), 5), Letter = letters[1 : 5]);  

kable(df) %>% group_rows(index = table(fct_inorder(df$Group)), label_row_css = "text-align: left; border-top: double") %>% as.character() %>% display_html()

which gives :

enter image description here

I just wish I could remove the groups title in bold (Tree and Flower). But I think It's quite ok.

  • Related