R flextable proc_freq 删除计数

问题描述 投票:0回答:1

我想在弹性表中显示两个变量的交叉表,但只显示行/列/表百分比,而不显示计数。

例如,如果我运行以下代码

library(flextable)
proc_freq(mtcars,"cyl","gear",include.row_percent = FALSE,include.table_percent = FALSE )

我得到了带有列百分比和计数的交叉表。如何删除计数?

我意识到这不能用预先存在的选项来完成,但我希望很容易更改 proc_freq 函数以删除计数。查看该函数的代码,我不知道如何做到这一点。

有什么想法吗?

r pivot-table flextable
1个回答
0
投票

问题是您正在使用一个旨在计算和显示频率计数的函数,这可能解释了为什么没有选项可以抑制它们。您可以通过删除不需要的单元格中的文本块来使用

compose

proc_freq(mtcars, "cyl", "gear",
          include.row_percent = FALSE,
          include.table_percent = FALSE ) |>
  compose(i=c(1,3,5), j=2:6, as_paragraph('')) |>
  compose(i=7, j=1, as_paragraph('')) |>
  compose(i=2, j=6, part="header", as_paragraph(''))

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.