Waldir Leoncio
Waldir Leoncio

Reputation: 11341

Replacing colnames on a pandoc table

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.

Upvotes: 4

Views: 1635

Answers (1)

daroczig
daroczig

Reputation: 28632

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 
--------------------------

Upvotes: 1

Related Questions