简体   繁体   English

如何从 kableExtra kbl 表中删除 NA?

[英]How to remove NA's from a kableExtra kbl table?

When I run this code:当我运行此代码时:

library(kableExtra)

table %>%
  kbl(caption ="Table 3: Data for Difference Equation Estimation.",col.names = c("Location",
                           "Year",
                           "Price",
                           "Per Capita Quantity",
                           "$\\Delta{P}$",
                           "$\\Delta{Q}$")) %>%
  kable_styling(full_width = F, position = "left")

I get the following:我得到以下信息:

在此处输入图像描述

How can I remove the NAs?如何删除 NA?

knitr::kable() is the foundation of kableExtra::kbl() . knitr::kable()kableExtra::kbl()的基础。 If you look at the help documentation for knitr::kable() it says:如果您查看knitr::kable()的帮助文档,它会说:

Missing values (NA) in the table are displayed as NA by default.表中的缺失值 (NA) 默认显示为 NA。 If you want to display them with other characters, you can set the option knitr.kable.NA, eg options(knitr.kable.NA = '') to hide NA values.如果要与其他字符一起显示,可以设置选项 knitr.kable.NA,例如 options(knitr.kable.NA = '') 隐藏 NA 值。

Therefore you might try:因此,您可以尝试:

options(knitr.kable.NA = '')

table %>%
  kbl(caption = "Table 3: Data for Difference Equation Estimation.",
      col.names = c("Location",
                    "Year",
                    "Price",
                    "Per Capita Quantity",
                    "$\\Delta{P}$",
                    "$\\Delta{Q}$")) %>%
  kable_styling(full_width = F, 
                position = "left")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM