将ftable因素导出到html

时间:2019-03-04 08:43:23

标签: r html-table factors

我有一个根据pip3 install --user <package_name> 创建的表格

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时,我得到的结果没有任何因素,只是这里的图片中的数字

enter image description here

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

1 个答案:

答案 0 :(得分: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)))))