4

给定以下示例

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

我想&nbsp;用“年龄”代替。然而,

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

给出错误,因为length(colnames(tableWithMargins))等于 3。

4

1 回答 1

1

您不能为该列命名,尽管这确实是一个有趣的想法。请随时在 GH 上创建票证。在此之前,您可以应用以下技巧:

> 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 
--------------------------
于 2015-05-30T02:14:52.393 回答