R-按日期分组,然后按唯一ID求和

时间:2019-02-06 16:53:47

标签: r

这是我的代码-创建一个按日期过滤的仪表板。一个选项卡将显示我们的健康调查数据,另一个选项卡将显示实践后的加载数据。我从“ post.csv”的前3列中提取日期,名称,每日。然后,我想用数学创建并添加接下来的3列。

我首先遇到的问题是,我需要Daily_Load来汇总给定日期的特定运动员的数据。然后,我需要使用最近7天(包括所选日期)的每日负荷数据为每位运动员创建7天滚动总和。最后是28天的滚动总和/ 4和7天/ 28滚动。

再次感谢您的所有帮助!

library(shiny)
library(dplyr)
library(lubridate)
library(ggplot2)
library(DT)
library(zoo)
library(tidyr)
library(tidyverse)
library(data.table)
library(RcppRoll)

AM_Wellness <- read.csv("amwell.csv", stringsAsFactors = FALSE)
Post_Practice <- read.csv("post.csv", stringsAsFactors = FALSE)
Post_Data <- Post_Practice[, 1:3]
Daily_Load <- aggregate(Daily~ ., Post_Data, sum)
Acute_Load <- rollsum(Post_Data$Daily, 7, fill = NA, align = "right")
Chronic_Load <- rollsum(Post_Data$Daily, 28, fill = NA, align = "right")/4
Post_Data['Day Load'] <- aggregate(Daily~ ., Post_Data, sum)
Post_Data['7-Day Sum'] <- Acute_Load
Post_Data['28-Day Rolling'] <- Chronic_Load
Post_Data['Ratio'] <- Acute_Load/Chronic_Load

ui <- fluidPage(

  titlePanel("Dashboard"),

  sidebarLayout(
    sidebarPanel(
      dateInput('date',
            label = "Date",
            value = Sys.Date()
  ),
  selectInput("athleteInput", "Athlete", 
              choices = c("All"))

),

mainPanel(tabsetPanel(type = "tabs",
                      tabPanel("AM Wellness", tableOutput("amwell")),
                      tabPanel("Post Practice", tableOutput("post"))

)
)

) )

server <- function(input, output) {
  output$amwell <- renderTable({
datefilter <- subset(AM_Wellness, AM_Wellness$Date == input$date)
  }, hover = TRUE, bordered = TRUE, spacing = "xs", align = "c")

  output$post <- renderTable({
datefilter <- subset(Post_Data, Post_Data$Date == input$date)
  }, hover = TRUE, bordered = TRUE, spacing = "xs", align = "c")

}

shinyApp(ui = ui, server = server)

0 个答案:

没有答案