[R] xtable use plus minus

Duncan Mackay dulcalma at bigpond.com
Fri Sep 13 04:11:45 CEST 2013


Here is a start

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)))

# restructure data
ahead = a_table[1,]
atab <- data.frame(a_table[-1,])
for (j in 2:5) atab[,j]=trunc(as.numeric(atab[,j]))

names(atab) <- ahead
atab
       X1 X2 X3 X4 X5
1  apples 17  2  3  1
2 oranges  3  2 18  3


  print(
  xtable(atab,
         digits = rep(0,6),
         ),
         type    = "latex",
         tabular.environment = "tabular",
         include.rownames = FALSE,
         include.colnames = TRUE,
         only.contents = TRUE, #NA.string = " ",
         hline.after = NULL
  ) ## xtable

% latex table generated in R 3.0.1 by xtable 1.7-1 package
% Fri Sep 13 12:04:31 2013
Fruits & Adam & errorA & steve & errorS \\ 
 apples & 17 & 2 & 3 & 1 \\ 
  oranges & 3 & 2 & 18 & 3 \\

You did not say how you wanted your output latex html ...

For latex you can use latex commands using new columntype to format \pm

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Sachinthaka Abeywardana
Sent: Friday, 13 September 2013 10:46
To: r-help at r-project.org
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