r - 将 ftable 因子导出到 html
问题描述
我有一个从创建的表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
,但是当我使用它时htmlTable
,我得到的结果没有任何因素,只有图片中的数字
如何恢复 htmltable 的因子名称?请注意,最终输出的行数和列数应与图片的输出相同,但行和列上需要有因子名称。
解决方案
我将首先将其转换为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)))))
推荐阅读
- node.js - NodeJS,快递。无法上传静态内容
- oracle - 将 OracleParameter 设置为 DbType.DateTimeOffset 时出现异常
- android - 隐藏带有覆盖黑条的状态栏
- python - Numpy删除值大于0的重复列
- java - 与复合键的可选单向一对一关系
- python - Python循环仅绘制分类变量
- android - 使微调器不可见但仍可以访问他选择的项目?
- python - python matplotlib.pyplot 不渲染时间序列图
- reactjs - 带有路由器的 ReactJS 应用程序可以托管在 S3 上并由 nginx 代理前端吗?
- python - 哪个更好地优化,以检查列表是否为空或只是迭代空列表?