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]]
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.
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.