xtable()保留R中的乳胶功能

时间:2013-07-03 15:09:02

标签: r xtable

我在R中生成一系列表格,一旦我用胶乳报告它们就会包含馏分。为此,我使用paste()函数在r中应用fraction命令,但是当我对它进行xtable时,它会在开头丢失“\ f”。下面是代码。你知道如何保留全部功能吗?感谢

x <- as.vector(rbind(1, paste("\frac{",1, "}{", 2, "}", sep ="" ))) 
y <- as.vector(rbind(2, paste("\frac{", 2, "}{", 3, "}", sep ="" )))    
table<- cbind(x,y)
xtable(table)

1 个答案:

答案 0 :(得分:4)

需要两件事;首先,加倍反斜杠,然后通过传递identity(只返回输入)来关闭通常的文本清理功能。

> x <- as.vector(rbind(1, paste("\\frac{",1, "}{", 2, "}", sep ="" ))) 
> y <- as.vector(rbind(2, paste("\\frac{",2, "}{", 3, "}", sep ="" )))    
> print(xtable(cbind(x,y)), sanitize.text.function=identity)
% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Wed Jul  3 10:17:21 2013
\begin{table}[ht]
\centering
\begin{tabular}{rll}
  \hline
 & x & y \\ 
  \hline
1 & 1 & 2 \\ 
  2 & \frac{1}{2} & \frac{2}{3} \\ 
   \hline
\end{tabular}
\end{table}