HARPgroup / om

Object-oriented Meta-model
0 stars 1 forks source link

Make om_flow_table accept custom probs #505

Open rburghol opened 1 year ago

rburghol commented 1 year ago

Something like this may work. Replace:

  for (i in index(month.abb)) {
    moname <- month.abb[i]
    drows <- sqldf(paste("select * from df2sum where ", mo_col, " = ", i))
    q_drows <- quantile(drows[,q_col], probs=c(0,0.05,0.1,0.25, 0.3, 0.5), na.rm=TRUE)
    q_mean <- mean(drows[,q_col])
    newline = data.frame(
      "Month" = moname,
      'Min' = round(as.numeric(q_drows["0%"]),rdigits),
      '5%' = round(as.numeric(q_drows["5%"]),rdigits),
      '10%' = round(as.numeric(q_drows["10%"]),rdigits),
      '25%' = round(as.numeric(q_drows["25%"]),rdigits), 
      '30%' = round(as.numeric(q_drows["30%"]),rdigits),
      '50%' = round(as.numeric(q_drows["50%"]),rdigits),
      'Mean' = round(q_mean,mrdigits),
      stringsAsFactors = FALSE
    )
    intake_summary_tbl <- rbind(intake_summary_tbl, newline)
  }
  names(intake_summary_tbl) <- c('Month', 'Min', '5%', '10%', '25%', '30%', '50%', 'Mean')

With:

  for (i in index(month.abb)) {
    moname <- month.abb[i]
    drows <- sqldf(paste("select * from df2sum where ", mo_col, " = ", i))
    q_drows <- quantile(drows[,q_col], probs=probs, na.rm=TRUE)
    q_mean <- mean(drows[,q_col])
    newline <- data.frame(Month = 1)
    newline[paste0(100 * probs,'%')] <- dline[paste0(100 * probs,'%')]
    newline["Mean"] <- q_mean
    intake_summary_tbl <- rbind(intake_summary_tbl, newline)
  }
  names(intake_summary_tbl) <- c('Month', probs, 'Mean')