答案1
R 会将列名转换为有效变量,这些变量不能包含空格。因此,当您编写:
mydf <- data.frame("Some heading"=c("One Two","Two","Three"))
它将“某些标题”转换为Some.heading
。要恢复空格,您需要明确声明名称:
names(mydf)=c("Some heading")
完整示例:
library(kableExtra)
library(knitr)
mydf <- data.frame("Some heading"=c("One Two","Two","Three"))
names(mydf)=c("Some heading")
kable(mydf,booktabs=T)
生成:
\begin{tabular}{l}
\toprule
Some heading\\
\midrule
One Two\\
Two\\
Three\\
\bottomrule
\end{tabular}