Dear R help:
I am trying to use paste(), within an ifelse() statement to insert latex commands into an object that has been created using xtable(). I cannot make the strings behave as I would like, the '\t' is creating a tab, the usual method of '\\t' is not working either - nor is any series of backslashes. The xtable object, I think, automatically alters the strings. How can I insert the literal '\textbf' into my xtable object? Any help would be appreciated. Code examples below.
Ryan

example 1:

> test= matrix(1:4, nrow=2,ncol=2)
> test = xtable(test)
> test[,1] = ifelse(test[,1]>1,paste('\textbf{',test[,1],'}'),test[,1])
> test
% latex table generated in R 2.5.1 by xtable 1.5-1 package
% Tue Sep 23 17:08:18 2008
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrr}
 \hline
& 1 & 2 \\
 \hline
1 & 1 &   3 \\
 2 &   extbf\{ 2 \} &   4 \\
  \hline
\end{tabular}
\end{center}
\end{table}

example 2:

> test= matrix(1:4, nrow=2,ncol=2)
> test = xtable(test)
> test[,1] = ifelse(test[,1]>1,paste('\\textbf{',test[,1],'}'),test[,1])
> test
% latex table generated in R 2.5.1 by xtable 1.5-1 package
% Tue Sep 23 17:11:56 2008
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrr}
 \hline
& 1 & 2 \\
 \hline
1 & 1 &   3 \\
 2 & $\backslash$textbf\{ 2 \} &   4 \\
  \hline
\end{tabular}
\end{center}
\end{table}


--
Ryan D. Enos

Department of Political Science
UCLA

http://renos.bol.ucla.edu/

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to