Nathan Torrance
2011-Mar-19 16:13 UTC
[R] Output a table formatted with standard deviations below means
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. 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]]
Jorge Ivan Velez
2011-Mar-19 18:22 UTC
[R] Output a table formatted with standard deviations below means
Hi Nathan, Do not know a direct way, but the following seems to work: # data means <- matrix(1:10,nrow=2) sds <- matrix(seq(0.1,1,by=0.1),nrow=2) colnames(means) <- colnames(sds) <- c("a","b","c","d","e") # adding "( )" to the SDs sdsn <- t(apply(sds, 1, function(x) paste('(', x, ')', sep = ""))) # formatting res <- do.call(rbind, lapply(1:nrow(means), function(i) rbind(means[i, ], sdsn[i, ]))) res # LaTeX require(xtable) xtable(res) *HTH,* *Jorge* * * On Sat, 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. > > 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@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. >[[alternative HTML version deleted]]
David Winsemius
2011-Mar-19 18:35 UTC
[R] Output a table formatted with standard deviations below means
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