根据R flexdashboard中数据表的过滤器计算平均值/平均值

时间:2020-04-14 16:35:43

标签: r datatable shiny flexdashboard

下面的代码在R flexdashboard中:

library(flexdashboard)
library(shiny)
library(DT)

renderDataTable({
  df <- data.frame(Month = c("2019-10-01", "2019-11-01", "2019-12-01", "2020-01-01", "2020-02-01", "2020-03-01"),
                 value1 = c(1, 2, 2, 4, 3, 1),
                 value2 = c(100, 200, 300, 400, 500, 600))

  DT::datatable(df,
                rownames = FALSE, filter = "top",
                options = list(autoWidth = FALSE,
                               lengthChange = FALSE,
                               lengthMenu = FALSE,
                               pageLength = FALSE,
                               paging = FALSE,
                               info = FALSE,
                               columnDefs = list(list(className = 'dt-center', targets = "_all")),
                               order = list(list(0, 'desc'))))
})

输出:

source

所需的输出: enter image description here

我想基于“ value1”列上的过滤器获取“ value2”,“ value3”,“ value4” ...的平均值。我已经尝试了来自matrixStats软件包的colMeans,但过滤时平均值不会改变。它只会显示整个列的平均值。

谢谢!

0 个答案:

没有答案
相关问题