【问题标题】:Converting pivottabler output to dataframe/array?将数据透视表输出转换为数据框/数组?
【发布时间】:2021-10-20 16:05:09
【问题描述】:

我正在使用 pivottabler 包,终于找到了我要找的桌子。但是,我无法进行更多计算/表格操作,因为表格位于 html 小部件中,而不是数据框中。使用 as.data.frame() 不起作用 - 有没有办法将其强制转换为数据帧?

编辑:错误代码显示:

"as.data.frame.default(pivoted) 中的错误: 不能将类'c("pivottabler", "htmlwidget")' 强制转换为 data.frame"

【问题讨论】:

    标签: html r dataframe r6 pivottabler


    【解决方案1】:

    pivottabler 包提供各种转换功能,包括到数据框:

    请看:
    http://pivottabler.org.uk/articles/v05-outputs.html#results-as-an-r-data-frame-1

    例子:

    library(pivottabler)
    pt <- PivotTable$new()
    pt$addData(bhmtrains)
    pt$addColumnDataGroups("PowerType")
    pt$addRowDataGroups("TOC")
    pt$defineCalculation(calculationName="TotalTrains", summariseExpression="n()")
    pt$evaluatePivot()
    df <- pt$asDataFrame()
    df
    

    数据框不支持合并的行/列标题,因此转换可能没有意义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-20
      • 2015-07-21
      • 1970-01-01
      相关资源
      最近更新 更多