[R] Math characters in column heading using latex() in Hmisc

Ista Zahn izahn at psych.rochester.edu
Mon Mar 14 13:36:33 CET 2011


Hi Christain,
You do not give us a reproducible example, nor do yo tell us how you
are creating the table. The following works fine for me:

dat <- data.frame(x1=1, x2=2, x3=3, x4=4)
names(dat) <- c("$\\sum_{i}\\sum_{j}C_{P,i,j,y}\\times\\mathit{FC}_{i}$",
"$XU_{alt,y}$","$n$","$\\bar{C}_{P,y}$")

library(Hmisc)
latex(dat)

on

R version 2.12.2 (2011-02-25)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8
 [5] LC_MONETARY=C             LC_MESSAGES=en_US.utf8
 [7] LC_PAPER=en_US.utf8       LC_NAME=C
 [9] LC_ADDRESS=C              LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] splines   stats     graphics  grDevices utils     datasets  methods
[8] base

other attached packages:
[1] xtable_1.5-6    Hmisc_3.8-3     survival_2.36-5

loaded via a namespace (and not attached):
[1] cluster_1.13.3  grid_2.12.2     lattice_0.19-17 tools_2.12.2

Best,
Ista

On Mon, Mar 14, 2011 at 8:33 AM, christiaan pauw <cjpauw at gmail.com> wrote:
> Hi Everybody
>
> I want to print a latex table containing math characters in the column
> heading
>
> These are the formulae I want to use as column headings. It prints OK from
> TeX
>
> $\sum_{i}\sum_{j}C_{P,i,j,y}\times\mathit{FC}_{i}$, $XU_{alt,y}$, $n$,
> $\bar{C}_{P,y}$
>
> My plan was to create a character vector with these and later rbind the
> values to them. When I create the vector like:
>
> Season=c("$\sum_{i}\sum_{j}C_{P,i,j,y}\times\mathit{FC}_{i}$","$XU_{alt,y}$"
> ,"$n$","$\bar{C}_{P,y}$")
>
> I get the error message:
>
> '\s' is an unrecognized escape in character string starting
>
> double backslashes doesn't give an error but doesn't work in Tex
> "$\\sum_{i}\\sum_{j}C_{P,i,j,y}\\times\\mathit{FC}_{i}$"
>
> Session Info below
>
> Thanks in advance
> Christiaan
>
>> sessionInfo()
> R version 2.11.1 (2010-05-31)
> x86_64-apple-darwin9.8.0
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] splines   grid      stats     graphics  grDevices utils     datasets
>  methods   base
>
> other attached packages:
>  [1] TeachingDemos_2.6 chron_2.3-35      reporttools_1.0.5 xtable_1.5-6
>  doBy_4.0.6        Hmisc_3.8-0       survival_2.35-8
>  [8] gdata_2.8.0       prettyR_1.8-1     reshape_0.8.3     plyr_1.2.1
>  proto_0.3-8
>
> loaded via a namespace (and not attached):
> [1] cluster_1.12.3     ggplot2_0.8.8      gtools_2.6.2       lattice_0.18-8
>    Matrix_0.999375-39 tools_2.11.1
>
>        [[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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list