[R] xtable use plus minus

arun smartpink111 at yahoo.com
Fri Sep 13 04:21:43 CEST 2013


Hi,
Also:


a_table[grep("\\d+",a_table)]<-paste0(sprintf("%.2f",as.numeric(a_table[grep("\\d+",a_table)])),"$\\pm$") # 2 d.p.
print(xtable(a_table),sanitize.text.function=identity)


A.K.

----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: Sachinthaka Abeywardana <sachin.abeywardana at gmail.com>
Cc: R help <r-help at r-project.org>
Sent: Thursday, September 12, 2013 9:29 PM
Subject: Re: [R] xtable use plus minus



Hi,
Try:
a_table[grep("\\d+",a_table)]<- paste0(a_table[grep("\\d+",a_table)],"$\\pm$")
library(xtable)
 print(xtable(a_table),sanitize.text.function=identity)
% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Thu Sep 12 21:26:45 2013
\begin{table}[ht]
\centering
\begin{tabular}{rlllll}
  \hline
 & 1 & 2 & 3 & 4 & 5 \\ 
  \hline
1 & Fruits & Adam & errorA & steve & errorS \\ 
  2 & apples & 17.1$\pm$ & 2.22$\pm$ & 3.2$\pm$ & 1.1$\pm$ \\ 
  3 & oranges & 3.1$\pm$ & 2.55$\pm$ & 18.1$\pm$ & 3.2$\pm$ \\ 
   \hline
\end{tabular}
\end{table}

A.K.



----- Original Message -----
From: Sachinthaka Abeywardana <sachin.abeywardana at gmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Thursday, September 12, 2013 8:46 PM
Subject: [R] xtable use plus minus

I am using a similar dataset to the following:

a= c("Fruits", "Adam","errorA", "steve", "errorS",
     "apples", 17.1,2.22, 3.2,1.1,
     "oranges", 3.1,2.55, 18.1,3.2 )
a_table=data.matrix(t(matrix(a,nrow=5)))

I would like to plus minus every second column starting from errorA (using
xtable/ hmisc)

example output (ignoring decimals):

Fruits && Adam && Steve \\
Apples && 17\pm 2 && 3 \pm 1 \\
Oranges && 3\pm 2 && 18 \pm 3\\

Additionally is there any way I can have just to 2 d.p.?

Thanks,
Sachin

    [[alternative HTML version deleted]]

______________________________________________
R-help at 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.




More information about the R-help mailing list