[R] Sweave, xtable plus/minus sign

Ottorino-Luca Pantani ottorino-luca.pantani at unifi.it
Tue Jun 29 17:08:19 CEST 2010

Dear R-users,
please consider the following minimal example:


<<label=test, echo=FALSE, results=tex>>=
df.data1 <-
  cbind.data.frame(A = rnorm(18),
                   B =factor(rep(LETTERS[1:6], each=3)))
myMean <- tapply(df.data1$A, df.data1$B, FUN = mean)
mySD <- tapply(df.data1$A, df.data1$B, FUN = sd)
foo <- matrix(c(myMean, mySD), ncol=2, nrow=6)
colnames(foo) <- c("Mean", "Std.Dev")
tmpTable <- xtable(foo, caption ="Simulated data",
     label="tab:four", digits=2)
print(tmpTable, caption.placement="top")


Is it possible to insert the plus/minus sign (±)  between the two columns ?
I mean within R/Sweave and not in the resulting .tex file ?

A possible workaround could be :
foo.df <- as.data.frame(foo)
foo.df$Std.Dev <- paste("±", round(mySD,2), sep="")
tmpTable <- xtable(foo.df, caption ="Simulated data",
     label="tab:five", digits=2)
print(tmpTable, caption.placement="top")

Any other solution?
Ottorino-Luca Pantani, Università di Firenze
Dip.to di Scienze delle Produzioni Vegetali,
del Suolo e dell'Ambiente Forestale (DiPSA)
P.zle Cascine 28 50144 Firenze Italia
Ubuntu 10.04 -- GNU Emacs (x86_64-pc-linux-gnu, GTK+ Version 
ESS version 5.8 -- R 2.10.1

More information about the R-help mailing list