我想在× 10表中提到一些小的数字,类似于code here。
以下是代码:
library(knitr)
library(kableExtra)
library(janitor)
x <- cbind(c("Term", "s(MERRA_WS)", "s(MERRA_T)", "s(MERRA_P)", "s(MERRA_WD)"),
c( "edf",
round(6.69852,2),
round(6.69852,2),
round(6.69852,2),
round(6.69852,2)),
c("Statistics",
round(6.69852,2),
round(6.69852,2),
round(6.69852,2),
round(6.69852,2)),
c("P-value", "$< 2 \\times 10^{-16}$","$< 2 \\times 10^{-16}$","$< 2 \\times 10^{-16}$","$< 2 \\times 10^{-16}$"),
c("Significance", "***", "***","***","***")
)
x <- as.data.frame(x) # set as dataframe
x <- janitor::row_to_names(x, 1, remove_rows_above = FALSE) %>% clean_names() # set the 1st row as header
rownames(x) <- NULL
x %>%
knitr::kable(digits = 2,
caption = "\\label{table:par-4} Estimates of parametric parameters for the modified model 4", align = c("l","c","c","c","c"),col.names = c("Term","edf", "Statistic", "P-value", "Significance"),
format = "latex", booktabs = T) %>% kable_styling(font_size = 8,
latex_options = "hold_position",
full_width = F) %>%
row_spec(0, bold = T) %>%
column_spec(1, border_right = F)下面是P值列没有转换为科学形式的输出:

我希望P值列中的输出如下所示:

发布于 2022-08-22 11:30:14
一个诀窍可能是在escape = FALSE中使用kable()。但你得小心点。根据文件,
当
= FALSE时,您必须确保特殊字符不会触发LaTeX或HTML中的语法错误。
这就是为什么我们必须手动将s(MERRA_WS)中的下划线转义为s(MERRA\\_WS)。
---
title: "P value formatting"
output: pdf_document
---
```{r setup, include=FALSE}knitr::opts_chunk$set(echo =真)
## R Markdown
```{r}图书馆(针织品)
图书馆(KableExtra)
图书馆(看门人)
图书馆(Rstatix)
X <- cbind(c(术语),"s(MERRA\_WS)","s(MERRA\_T)","s(MERRA\_P)","s(MERRA\_WD)"),
c( "edf", round(6.69852,2), round(6.69852,2), round(6.69852,2), round(6.69852,2)), c("Statistics", round(6.69852,2), round(6.69852,2), round(6.69852,2), round(6.69852,2)), c("P-value", "$< 2 \\times 10^{-16}$", "$< 2 \\times 10^{-16}$", "$< 2 \\times 10^{-16}$", "$< 2 \\times 10^{-16}$"), c("Significance", "***", "***","***","***") )X <- as.data.frame(x)
X <- janitor::row_to_names(x,1,remove_rows_above = FALSE) %>% clean_names()
行名(X) <- NULL
X %>%
针织品::kable(数字= 2,
caption = "\\label{table:par-4} Estimates of parametric parameters for the modified model 4", align = c("l","c","c","c","c"), col.names = c("Term","edf", "Statistic", "P-value", "Significance"), format = "latex", booktabs = T, escape = FALSE) %>% kable_styling(font_size = 8,
latex_options = "hold_position", full_width = F) %>% row_spec(0,粗体= T) %>%
column_spec(1,border_right = F)

发布于 2022-08-22 11:15:13
library(tidyverse)
library(knitr)
tibble(PValue="2 x 10^-16^") %>% kable()在标记文档中的块中生成

如上面可能的重复所示。
https://stackoverflow.com/questions/73443963
复制相似问题