将ftable因素导出为html

问题描述 投票:0回答:1

我有一张从ftable()创建的表

structure(c(1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 
1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
0L, 1L, 0L, 2L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 
0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 
0L, 0L, 1L, 0L, 0L, 0L, 0L), .Dim = c(12L, 7L), class = "ftable", row.vars = list(
    ï..petal_size = c("large ", "small", "small "), stem_length = c("long", 
    "long ", "short", "short ")), col.vars = list(flow_color = c("blue", 
"green", "indigo ", "orange", "red  ", "violet", "yellow")))

我想使用htmlTable导出它,但是当我使用htmlTableon时,我得到的结果没有任何因素,只有数字如图所示

enter image description here

如何恢复htmltable的因子名称?请注意,最终输出应具有与图片输出相同的行数和列数,但需要在行和列上包含因子名称。

r html-table factors
1个回答
0
投票

我将它首先转换为data.frame并添加必要的调整以获得所需的输出:

tableToHtml <-structure(c(1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
            0L, 0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 
            1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
            0L, 1L, 0L, 2L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 
            0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 
            0L, 0L, 1L, 0L, 0L, 0L, 0L), .Dim = c(12L, 7L), class = "ftable", row.vars = list(
              ï..petal_size = c("large ", "small", "small "), stem_length = c("long", 
                                                                              "long ", "short", "short ")), col.vars = list(flow_color = c("blue", 
                                                                                                                                           "green", "indigo ", "orange", "red  ", "violet", "yellow")))

 library(htmlTable)

 htmlTable(as.data.frame(tableToHtml),rnames=F, header=rep("", length(colnames(as.data.frame(tableToHtml)))))
© www.soinside.com 2019 - 2024. All rights reserved.