4

Given the following example

library(pander)
table <- Titanic[1, 1, , ]
tableWithMargins <- addmargins(table)
pander(tableWithMargins)

----------------------------
  &nbsp;     No   Yes   Sum 
----------- ---- ----- -----
 **Child**   0     5     5  

 **Adult**  118   57    175 

  **Sum**   118   62    180 
----------------------------

I would like to substitute &nbsp; with "Age". However,

colnames(tableWithMargins) <- c("Age", "No", "Yes", "Sum")

Gives an error, because length(colnames(tableWithMargins)) equals 3.

Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
  • 2
    That value seem to be hard coded in the `pander:::pandoc.table.return` function where the formatting happens. Unless I missed something, it doesn't look like it's easy to replace. – MrFlick May 29 '15 at 21:01

1 Answers1

1

You cannot give a name to that column, although it's indeed an interesting idea. Please feel free to create a ticket on GH. Until then, you can apply the following hack:

> tableWithNoRowNames <- cbind(data.frame(Age = rownames(tableWithMargins), tableWithMargins))
> rownames(tableWithNoRowNames) <- NULL
> emphasize.strong.cols(1)
> pander(tableWithNoRowNames)

--------------------------
   Age     No   Yes   Sum 
--------- ---- ----- -----
**Child**  0     5     5  

**Adult** 118   57    175 

 **Sum**  118   62    180 
--------------------------
daroczig
  • 28,004
  • 7
  • 90
  • 124