Skip to content

Commit

Permalink
discard unnecessary calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
nemeth committed Jan 8, 2021
1 parent 5d44198 commit 79264de
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -830,26 +830,26 @@ server=function(input,output,session){
#### measures
cols=colnames(data)[5:16]
#### Weekly averages (across years)
meandata=data[Year %in% c(input$period[1]:input$period[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Week,Sex)]
meandata=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Week,Sex)]

dataset$meandata=meandata
#### Expected level (average of weekly averages)
expectedlevel=data[Year %in% c(input$period[1]:input$period[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]
expectedlevel=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]


#### summer ####
if (input$country %in% c("AUS2","CHL","NZL_NP")){
expectedlevelsummer=data[Year %in% c(input$period[1]:input$period[2]) & !(Week %in% 22:38), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]
expectedlevelsummer=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]) & !(Week %in% 22:38), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]

} else {
#### Expected level without winter season (from December to March included - week 48 -- week 12)
expectedlevelsummer=data[Year %in% c(input$period[1]:input$period[2]) & !(Week %in% c(1:12,48:52)), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]
expectedlevelsummer=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]) & !(Week %in% c(1:12,48:52)), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]

}


#### lower quartile
q25data=data[Year %in% c(input$period[1]:input$period[2]), lapply(.SD,quantile,prob=0.25), .SDcols= cols, by = list(CountryCode,Week,Sex)]
q25data=data[CountryCode %in% input$country & Year %in% c(input$period[1]:input$period[2]), lapply(.SD,quantile,prob=0.25), .SDcols= cols, by = list(CountryCode,Week,Sex)]
dataset$q25data=q25data
#### linear trend expectation

Expand All @@ -869,23 +869,23 @@ server=function(input,output,session){

if (input$extracountry == TRUE) {

meandata2=data[Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Week,Sex)]
meandata2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Week,Sex)]

dataset$meandata2=meandata2
#### Expected level (average of weekly averages)
expectedlevel2=data[Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]
expectedlevel2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]

if (input$country2 %in% c("AUS2","CHL","NZL_NP")){
expectedlevelsummer2=data[Year %in% c(input$period2[1]:input$period2[2]) & !(Week %in% 22:38), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]
expectedlevelsummer2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]) & !(Week %in% 22:38), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]

} else {
#### Expected level without winter season (from December to March included - week 48 -- week 12)
expectedlevelsummer2=data[Year %in% c(input$period2[1]:input$period2[2]) & !(Week %in% c(1:12,48:52)), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]
expectedlevelsummer2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]) & !(Week %in% c(1:12,48:52)), lapply(.SD,mean), .SDcols= cols, by = list(CountryCode,Sex)]

}

#### lower quartile
q25data2=data[Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,quantile,prob=0.25), .SDcols= cols, by = list(CountryCode,Week,Sex)]
q25data2=data[CountryCode %in% input$country2 & Year %in% c(input$period2[1]:input$period2[2]), lapply(.SD,quantile,prob=0.25), .SDcols= cols, by = list(CountryCode,Week,Sex)]
dataset$q25data2=q25data2


Expand Down

0 comments on commit 79264de

Please sign in to comment.