[R] Output a table formatted with standard deviations below means

David Winsemius dwinsemius at comcast.net
Sat Mar 19 19:35:39 CET 2011


On Mar 19, 2011, at 12:13 PM, Nathan Torrance wrote:

> Is it in bad form to double post to StackOverflow and R-help?  
> Apologies if
> so. Here's my task:
>
> I've got a matrix of means like so
>
> means<-matrix(1:10,nrow=2)
> colnames(means)<-c("a","b","c","d","e")
>
> and a matrix of standard deviations like so
>
> sds<-matrix(seq(0.1,1,by=0.1),nrow=2)
> colnames(sds)<-c("a","b","c","d","e")
>
> and I want to output a Latex (or HTML) table where the standard  
> deviations
> appear in parens just below the corresponding means.

require(Hmisc)
mtx <-  matrix(c( means[1,], paste("(",sds[1,],")"), means[2,],  
paste("(",sds[2,],")")), nrow=4, byrow=TRUE)
colnames(mtx)<-colnames(means)
latex(mtx)

-- 
David

>
> Something like this:
>
>    a    &   b    &  c    &  d    &  e \\
>    1    &   3    &  5    &  7    &  9 \\
>  (0.1)  &  (0.3) & (0.5) & (0.7) & (0.9) \\
>    2    &   4    &  6    &  8    &  10 \\
>  (0.2)  &  (0.4) & (0.6) & (0.8) & (1.0) \\
>
> except in proper Latex (or HTML).
>
> How can I do this from R?
>
> Someone mentioned the "apsrtable" package but that seems to require my
> having a model object.
>
> Thanks in advance folks.
>
> 	[[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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list