How do you remove the cell label from your table?

柔情痞子 提交于 2020-01-24 22:11:47

问题


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!


回答1:


"|" 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()


来源:https://stackoverflow.com/questions/58874633/how-do-you-remove-the-cell-label-from-your-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!