![R Sweave 中 data.frame 中的空格](https://linux22.com/image/407939/R%20Sweave%20%E4%B8%AD%20data.frame%20%E4%B8%AD%E7%9A%84%E7%A9%BA%E6%A0%BC.png)
答案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}