如下面的MWE所示,香蕉量的NA如何变成空白而不是显示" NA"?我希望数字列像字符列一样工作(参见MWE中的苹果颜色)。
library(data.table)
library(flextable)
the.data <- data.table(Fruit=c("Apples", "Oranges", "Bananas", "Pears"), Amount=c(4L, 8L, NA_integer_, 2L), Color=c(NA_character_, "Orange", "Yellow", "Green"))
the.ft <- flextable(the.data)
the.ft
一种方法是将数字列转换为字符,但也许有更好的方法。
答案 0 :(得分:3)
我将努力将该案例整合到包中。同时,以下代码可让您显示NA的空白。
library(flextable)
the.data <- data.table(
Fruit=c("Apples", "Oranges", "Bananas", "Pears"),
Amount=c(4L, 8L, NA_integer_, 2L),
Color=c(NA_character_, "Orange", "Yellow", "Green"))
the.ft <- regulartable(the.data)
the.ft <- set_formatter(
the.ft,
Amount = function(x) ifelse(is.na(x), "", sprintf("%d", x) ),
Color = function(x) ifelse(is.na(x), "", x )
)
the.ft
答案 1 :(得分:1)