rr-flextablejanitor

How do I hide a percentage column on my flextable?


I have a simple table that I want to produce and only show counts, no percentages which is what flextable defaults to. I can't find a similar question on here or while reading through the package documentation.

new_data <- df %>% 
  group_by(var1, var2) %>% 
  select(var1, var2) %>% 
  tabyl(var2) %>% 
  arrange(desc(n)) %>% 
  flextable() %>% 
  print()

Solution

  • This has nothing to do with flextable. It's janitor::tably which adds the percentage column which is then displayed in your flextable. If you don't want percentages you could use dplyr::count instead to create your frequency table.

    Using a minimal reproducible example based on mtcars.

    library(flextable)
    library(dplyr)
    
    mtcars %>% 
      count(cyl) %>% 
      arrange(desc(n)) %>% 
      flextable()
    

    enter image description here