【问题标题】:How to get rid of total row and total column in rpivot table如何摆脱数据透视表中的总行和总列
【发布时间】:2017-07-16 18:11:36
【问题描述】:

这只是一个示例代码。我想删除数据透视表中名为“Total”的最后一行和最后一列。您的帮助将不胜感激。谢谢。

library(devtools)
install_github("ramnathv/htmlwidgets") 
install_github("smartinsightsfromdata/rpivotTable")
## Load rpivotTable
library(rpivotTable)
data(mtcars)
## One line to create pivot table
rpivotTable(mtcars, rows="gear", col="cyl", aggregatorName="Average", 
            vals="mpg", rendererName="Treemap")

【问题讨论】:

    标签: r shiny shiny-server shinyjs


    【解决方案1】:

    你可以试试:

    data <-rpivotTable(mtcars, rows="gear", col="cyl", aggregatorName="Average", 
                vals="mpg", rendererName="Treemap")
    

    删除最后一行:

    data <- data[-nrow(data), ]
    

    删除最后一列/特定列名:

    ## drop column of specific name
    drop <- "Total"
    data[, !(names(data) %in% drop)]
    ## drop last column
    data[, -ncol(data)]
    

    同时放下两个:

    data[-nrow(data), !(names(data) %in% drop)]
    

    data[-nrow(data), -ncol(data)]
    

    【讨论】:

    • 优秀。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 2018-10-04
    • 1970-01-01
    • 2018-09-15
    • 2023-04-04
    • 2022-10-23
    相关资源
    最近更新 更多