Hello everyone, Peter (see my earlier post) recommended the following script for finding the means and standard deviations and putting them in table form. However, I would like the standard deviations under the means in brackets. Can anyone check this code to see how this can be adjusted? 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) -- Thanks, Jim. [[alternative HTML version deleted]]
On Jul 21, 2011 Jim Silverton wrote:> However, I would like the standard deviations under the means in brackets. > Can anyone check this code to see how this can be adjusted?Jim, You need to use "underset," a LaTeX command. The bare-bones call is $\underset{}{}$, where the underset value goes in the first curly and your main value goes in the second curly (i.e. is typeset above the underset). I don't use xtable but rather use Ron Harrell's functions in Hmisc package, then pass it through his latex() function, so can't take you further. ## paste('$\\underset','{',data$SDs,'}','{',data$means,'}$', sep="") Hope this gets you going. Regards, Mark. ----- Mark Difford (Ph.D.) Research Associate Botany Department Nelson Mandela Metropolitan University Port Elizabeth, South Africa -- View this message in context: http://r.789695.n4.nabble.com/Latex-Table-Help-on-R-tp3682951p3683038.html Sent from the R help mailing list archive at Nabble.com.
On 2011-07-20 23:50, Jim Silverton wrote:> Hello everyone, > Peter (see my earlier post) recommended the following script for finding the > means and standard deviations and putting them in table form. > > However, I would like the standard deviations under the means in brackets. > Can anyone check this code to see how this can be adjusted? > > > 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) >You can use the same idea to construct an appropriate matrix: matm <- matrix(round(means, 2), 2, 2) mats <- matrix(paste("(",round(sds, 2),")"), 2, 2) mat <- rbind(matm, c(" "," "), mats) # note the spaces mat <- mat[c(1,4,3,2,5), ] colnames(mat) <- c("Dataset1","Dataset2") rownames(mat) <- c("Var1", " ", " ", "Var2", " ") # note 1,2,3 spaces to make rownames unique mat.tb <- xtable(mat, align=c("r","c","c")) mat.tb Peter Ehlers