1

我正在尝试利用 expss 来自动化目前通过 R 在 Excel 中完成的一些报告。我通常需要总结一些相对于某些字段(列)的分组(行)中的许多值。我发现很难摆脱单元格描述。

这是一个例子:

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

您会看到“身高”被打印为标签,请问我该如何摆脱它?

谢谢!

4

1 回答 1

2

“|” 分配为标签抑制标签和变量名称:

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()
于 2019-11-15T12:48:50.230 回答