1

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!

codesaurus
  • 81
  • 6

1 Answers1

2

"|" 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()
Gregory Demin
  • 4,596
  • 2
  • 20
  • 20
  • That works for the name of the stat, but what about the term "cell_var" that appears in this example: `htmlTable(mpg %>% tab_rows(model) %>% tab_cols(drv) %>% tab_stat_sum() %>% tab_pivot())` – Ben Dec 16 '19 at 16:53
  • @Ben `cell_var` is default value from missing term `tab_cells` in the chain. `tab_rows` is for tables rows, `tab_cols` as you see, columns, and `tab_cells` are variables on which we calculate statistics. – Gregory Demin Dec 16 '19 at 18:55