首页 > 解决方案 > 如何将行名添加到弹性表?

问题描述

无法让 add.rownames = TRUE 在 flextable 中工作

> tabelM
  Man Vrouw
  Gaat wel       337   442
  Goed              935  1150
  Slecht              57    83
  Zeer goed    262   243
  Zeer slecht    14    10

> rownames(tabelM)
[1] "Gaat wel"    "Goed"        "Slecht"      "Zeer goed"   "Zeer slecht"

> colnames(tabelM)
[1] "Man"   "Vrouw"


> flextable(tabelM)
#works fine


> flextable(tabelM,add.rownames = TRUE)

flextable 中的错误(tabelM,add.rownames = TRUE):未使用的参数(add.rownames = TRUE)

标签: r

解决方案


您可以将此解决方法与软件包tibbledplyr

library(dplyr)
library(tibble)
flextable(tabelM %>% rownames_to_column("column name"))

正如评论中已经提到的,flextable没有名为add.rownames的参数


推荐阅读