Search code examples
expss

How do you remove the cell label from your table?


I'm trying to leverage expss to automate some reporting currently done in Excel via R. I'm generally needing to summarise a lot of values across some grouping (rows) relative to some fields (columns). I'm finding it difficult to get rid of the cell description.

Here's an example:

animals <- data.table(
  animal = c(1, 1, 2, 2, 3, 3, 4, 4),
  standing = c(1, 2, 1, 2, 1, 2, 1 ,2),
  height = c(50, 70, 75, 105, 25, 55, 10, 20)
)

animals <- expss::apply_labels(
  animals,
  animal = "animal",
  animal = c("cat" = 1, "dog" = 2, "turtle" = 3, "rat" = 4),
  standing = "standing",
  standing = c("no" = 1, "yes" = 2),
  height = "height"
)

expss::expss_output_viewer()

animals %>%
  expss::tab_cells(height) %>%
  expss::tab_cols(animal) %>%
  expss::tab_rows(standing) %>% 
  expss::tab_stat_sum(label = "") %>%
  expss::tab_pivot()

You will see that "height" is printed as a label, how do I get rid of it please?

Thanks!


Solution

  • "|" assigned as label suppress both label and variable name:

    library(expss)
    animals <- data.table(
        animal = c(1, 1, 2, 2, 3, 3, 4, 4),
        standing = c(1, 2, 1, 2, 1, 2, 1 ,2),
        height = c(50, 70, 75, 105, 25, 55, 10, 20)
    )
    
    animals <- expss::apply_labels(
        animals,
        animal = "animal",
        animal = c("cat" = 1, "dog" = 2, "turtle" = 3, "rat" = 4),
        standing = "standing",
        standing = c("no" = 1, "yes" = 2),
        height = "|"  # to suppress label
    )
    
    expss::expss_output_viewer()
    
    animals %>%
        expss::tab_cells(height) %>%
        expss::tab_cols(animal) %>%
        expss::tab_rows(standing) %>% 
        expss::tab_stat_sum(label = "") %>%
        expss::tab_pivot()