[R] Latex Table for means and standard deviations in brackets
Peter Lomas
peter.lomas at ucalgary.ca
Wed Jul 20 23:22:05 CEST 2011
Hi Jim,
Perhaps somebody else knows a smoother way, but in the past I have
just built my table in R as a matrix then used xtable. Here's what I
would do with your example:
library(xtable)
dataset1 = matrix( c(1,2,3,4, 5, 6 ), 2 , 3)
dataset2 = matrix( c(4,3,5,10, 1, 0), 2, 3)
dataset <- rbind(dataset1,dataset2) #combine dataset
means <- apply(dataset,1,mean) #calculate row means
sds <- apply(dataset,1,sd) #calculate row standard deviation
msd <- paste(round(means,2)," (",round(sds,2),")",sep="") #mean and
standard deviation
rn <- c("Var1","Var2") #rownames
cn <- c("Dataset1","Dataset2") #column names
tab <- matrix(msd,2,2,dimnames=list(rn,cn))
tab
Dataset1 Dataset2
Var1 "3 (2)" "3.33 (2.08)"
Var2 "4 (2)" "4.33 (5.13)"
xtable(tab)
If there is a better way, I'd love to know it myself.
Peter
On Wed, Jul 20, 2011 at 04:05, Jim Silverton <jim.silverton at gmail.com> wrote:
> Hello all,
> I am new to xtable. I have several datasets in the form of matrices.
> Consider the following two simple datasets which are 2 x 3 matrices. The
> rows in both matrices have the same meaning. For example the first row of
> both matrices are variable 1 and the second row of both matrices are
> variable 2.
>
> dataset1 = matrix( c(1,2,3,4, 5, 6 ), 2 , 3)
> dataset2 = matrix( c(4,3,5,10, 1, 0), 2, 3)
>
>
> I would like to find the means and standard deviations in brackets for
> each data set in the form of a table that looks like:
>
> dataset1 dataset2
> var1 2 3
> (1.3) (2.5)
> var2 4 10
> (2.3) (1.2)
>
> ( I used the wrong numbers). But does anyone has any idea how Xtable or some
> other R package can automatically create the latex table?
>
>
>
>
>
> --
> Thanks,
> Jim.
>
> [[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