繁体   English   中英

如何避免乳胶中的索引(编号)?

[英]How to avoid index (numbering) in latex?

我正在研究Latex和R,并使用以下代码。

<<echo=FALSE>>=
infile<-read.table("test.txt",sep="\t")
Col3 <- unique(infile[,3]) 
LCol3 <- length(Col3)
for (i in 1:LCol3) {


print(paste("Column", Col3[i]))
print(infile[infile[,3]==Col3[i],-3])
}
@

我得到以下输出。

1] "Column C"
V1 V2 V4
1 A B D
2 X T K
[1] "Column Z"
V1 V2 V4
3 Z U M
4 E V R
5 Z U M
[1] "Column P"
V1 V2 V4
6 E V R

我想避免编号和列名。 我希望我的输出如下。

"Column C"
A B D
X T K

"Column Z"
Z U M
E V R
Z U M

"Column P"
E V R

我该怎么做?

通常, print是您尝试执行的错误工具。 您可能应该改用cat 由于您的示例不可复制,因此以下是一个非常简单的示例,说明了一些类似的用法:

d <- data.frame(V1 = LETTERS[1:5],V2 = letters[1:5], V3 = 1:5)

for (i in 1:5){
    cat("Row",i,"\n")
    cat(unlist(d[i,]),"\n\n")
}

Row 1 
A a 1 

Row 2 
B b 2 

Row 3 
C c 3 

Row 4 
D d 4 

Row 5 
E e 5 

请注意,需要取消列出数据框行,以使cat能够明智地将各个元素粘贴在一起。

欢迎使用stackoverflow @Manish。
至于删除编号,请使用latexrowname=FALSE 见下文...数据

Age  <- c(rep('Young',2),rep('Middle',2),rep('Old',2));Age
Smoker  <- rep(c('Yes','No'),3);Smoker
Died <- c(5,6,92,59,42,165);sum(Died)
Lived <- c(174,213,262,261,7,28);sum(Lived)
smoke <- data.frame(Age,Smoker,Died,Lived);smoke

print(xtable(smoke),file ='ttt.tex')$结果打印在ttt.tex文件中
这给

 $\begin{table}[ht]
    \begin{center}
    \begin{tabular}{rllrr}
      \hline
     & Age & Smoker & Died & Lived \\ 
      \hline
    1 & Young & Yes & 5.00 & 174.00 \\ 
      2 & Young & No & 6.00 & 213.00 \\ 
      3 & Middle & Yes & 92.00 & 262.00 \\ 
      4 & Middle & No & 59.00 & 261.00 \\ 
      5 & Old & Yes & 42.00 & 7.00 \\ 
      6 & Old & No & 165.00 & 28.00 \\ 
       \hline
    \end{tabular}
    \end{center}$

要么 使用print和xtable输出

在Hmisc中使用乳胶
names(smoke)<-NULL Latex(smoke,file ='ttt.tex',rowname = NULL)
我们得到

 $\begin{table}[!tbp]
\begin{center}
\begin{tabular}{llrr}
\hline\hline
\multicolumn{1}{c}{Age}&\multicolumn{1}{c}{Smoker}&\multicolumn{1}{c}{Died}&\multicolumn{1}{c}{Lived}\tabularnewline
\hline
Young&Yes&$  5$&$174$\tabularnewline
Young&No&$  6$&$213$\tabularnewline
Middle&Yes&$ 92$&$262$\tabularnewline
Middle&No&$ 59$&$261$\tabularnewline
Old&Yes&$ 42$&$  7$\tabularnewline
Old&No&$165$&$ 28$\tabularnewline
\hline
\end{tabular}
\end{center}

要么, 使用乳胶功能Hmisc输出

我想您已经知道,您需要在块选项字段中添加results=tex才能在其中使用乳胶,以便获得tex输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM