[R] Hmisc's latex: na.blank and grouping not working as expected

Marius Hofert marius.hofert at math.ethz.ch
Thu May 3 06:56:32 CEST 2012


I forgot to say what 'rmNames' is:

rmNames <- function(x) {x[c(FALSE, x[-1]==x[-length(x)])] <- ""; x} 

With 

rmNames <- function(x) {x[c(FALSE, x[-1]==x[-length(x)])] <- NA; x} 

the option na.blank=TRUE works as expected. Also, the two empty columns are inserted due to "cgroup", but I don't know how to avoid this.

On 2012-05-02, at 09:26 , Marius Hofert wrote:

> Dear expeRts,
> 
> Why does na.blank=TRUE not replace the NA's in the following LaTeX table?
> 
> x <- matrix(1:72, ncol=4, nrow=8)
> colnames(x) <- c("gr1.sgr1", "gr1.sgr2", "gr2.sgr1", "gr2.sgr2")
> rn <- apply(expand.grid(beta=c(0.25, 0.75), n=c(100, 500), d=c(10, 100))[, 3:1], 2, rmNames)
> x <- cbind(rn, x) # append columns containing the row labels
> x[2,5] <- NA
> stopifnot(is.na(x[2,5]))
> 
> require(Hmisc)
> latex(x,
>      file="",
>      na.blank=TRUE,
>      rowlabel=c("d", "n", "beta"),
>      booktabs=TRUE)
> 
> In the end, I would like to have the columns displayed in groups like this:
> 
>                        Group 1                     Group 2
> d   n   beta   Sub-group 1   Sub-group 2   Sub-group 1   Sub-group 2
> 10  100 0.25       1             9
>        0.75       2
>    500 0.25       3            10
>        0.75       4            11             ...           ...
> 100 100 0.25       5            12
>        0.75       6            13
>    500 0.25       7            ...
>        0.75       8
> 
> If anybody knows how to do this, please let me know :-) This is (one of) my trial(s):
> 
> latex(x,
>      file="",
>      cgroup=c("", "Group 1", "Group 2"),
>      n.cgroup=c(3, 2, 2),
>      na.blank=TRUE,
>      rowlabel=c("d", "n", "beta"),
>      booktabs=TRUE)
> 
> Why are there two empty columns inserted and the table has suddenly 9 columns instead of 7?
> 
> Cheers,
> 
> Marius
> 



More information about the R-help mailing list