我将使用kable函数创建一个相当大的HTML表格,其中有很多0。为了更清晰地显示相关信息,我正在尝试通过用空格替换它们来隐藏表格中的0。
目前,我正在尝试以下方式,但它不起作用:
除了“-”将被替换为空格而不是破折号外。
编辑2:没关系,我已经搞定了,尽管这很不正规。
目前,我正在尝试以下方式,但它不起作用:
my_table = knitr::kable(...)
cat(gsub(0," ",my_table), sep = '\n')
类似于上述方法可以去除缺失值,但是我似乎无法使用它来去除0的值。
提前感谢您的帮助!
编辑:数据示例:
Product = c('A','B','A','A','C','B')
Month = c('Jan', 'Feb', 'Feb', 'Apr', 'Jan', 'Feb')
my_data = data.frame(Product, Month)
my_table = table(my_data)
kable(my_table) #This has the 0's which I don't want
Product | Month
A | Jan
B | Feb
A | Feb
A | Apr
C | Jan
B | Feb
当前输出:
----Jan Feb Mar Apr
A 1 1 0 1
B 0 2 0 0
C 1 0 0 0
期望输出:
----Jan Feb Mar Apr
A 1 1 - 1
B - 2 - -
C 1 - - -
除了“-”将被替换为空格而不是破折号外。
编辑2:没关系,我已经搞定了,尽管这很不正规。
my_kable = knitr::kable(my_table)
gsub(0, ' ', my_kable)
笑死了
knitr::kable()
中吗? - Phil"0"
。 - missusedata.frame("Product" = LETTERS[1:4], etc.)
- Phil