下面的代码在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'))))
})
输出:
我想基于“ value1”列上的过滤器获取“ value2”,“ value3”,“ value4” ...的平均值。我已经尝试了来自matrixStats软件包的colMeans
,但过滤时平均值不会改变。它只会显示整个列的平均值。
谢谢!