'r kable replace 0.0 with blank or "-" and keep it as numeric
I have this little table:
cases <- c("1182025", "+19525")
deceased <- c("7639", "+25")
TI_7 <- c(1100.395332, 0.0)
df <- data.frame(cases, deceased, TI_7)
If I kable it, the 0.0 in the third column should not appear.
If possible, the data type of the third column should remain numeric, otherwise decimal.mark = ',' does not work.
This is how I kable:
kbl(df, format.args = list(decimal.mark = ',', digits=6), align = "rccc") %>%
kable_paper(bootstrap_options = "striped", full_width = F, position = "left")
I tried it with gsub, but then all the 0s disappear, inside the numbers too.
With other functions the data type changes to unknown.
Solution 1:[1]
Ok this seems to work:
df <- na_if(df, 0)
options(knitr.kable.NA = '')
kbl(df, format.args = list(decimal.mark = ',', digits=6), align = "rccc") %>%
kable_paper(bootstrap_options = "striped", full_width = F, position = "left")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Katja |

