R/code_sql_roll_up_samples.R

Defines functions code_sql_roll_up_samples

Documented in code_sql_roll_up_samples

#' Rolls up Sample Years
#'
#' Selects distinct examinees with the highest score
#' @param years the years to roll up
#' @param sample_function function that makes a sample for a single year
#' @return A data frame with distinct cohort records
#' @export

code_sql_roll_up_samples <- function(years, sample_function) {

  sql <- sample_function(years[1])
  l <- length(years)
  if (l > 1)
    for (i in 2:l)
      sql <- sprintf("%s UNION %s", sql,
                     sample_function(years[i]))
  sql

}
mattjcamp/cohortr documentation built on May 21, 2019, 1:24 p.m.