How to remove the name of first column of a table with collapse rows with rmarkdown and kableExtra

I'm doing a table with a combination of collapsed and packed rows. I want to remove the name the frist of the column, but when I do so kable removes the collapsing.

Any ideas?

Here an reproducible example code with the same errror:

library(tidyverse)
library(kableExtra)

data("iris") 

Tbl <- iris %>% 
  pivot_longer(cols = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)) %>% 
  separate(name, sep = 5, into = c("Flower_part", "Measure")) %>% 
  group_by(Species, Flower_part, Measure) %>% 
  summarise(Mean = mean(value),
            SD = sd(value)) 

#Table with colapsed rows and the name of column
Tbl %>% 
  ungroup() %>% 
  select(-Species) %>% 
  kbl(digits = 3) %>%
  kable_classic("striped", full_width = T) %>% 
  collapse_rows(columns = 1, valign = "top") %>% 
  pack_rows(index = table(Tbl$Species), indent = FALSE)

#Table with a "blank" name with the collapsing not working.
Tbl %>% 
  ungroup() %>% 
  select(-Species) %>% 
  rename(" " = "Flower_part") %>%
  kbl(digits = 3) %>%
  kable_classic("striped", full_width = T) %>% 
  collapse_rows(columns = 1, valign = "top") %>% 
  pack_rows(index = table(Tbl$Species), indent = FALSE)

In the time the post got get the approval, I've been given a solution using unicode:

Tbl %>% 
  ungroup() %>% 
  select(-Species) %>% 
  rename("\U00A0" = "Flower_part") %>%
  kbl(digits = 3) %>%
  kable_classic("striped", full_width = T) %>% 
  collapse_rows(columns = 1, valign = "top") %>% 
  pack_rows(index = table(Tbl$Species), indent = FALSE)

Is there no "native" solution?

1 Like

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.