R/filter_dates.R

Defines functions shift_values_range filter_dates

Documented in filter_dates shift_values_range

#===============================================================================
#' @title filter_dates
#'
#' @description remove values from a data.table (non-equi join filter)
#'
#' @author Jonathan Kennel \email{[email protected]}
#'
#' @param dat data.table to filter (name, datetime)
#' @param filt data.table of filter start and end times (start, end)
#' @param keep include or exclude the subsets
#'
#' @return filtered data.table
#'
#' @export
#===============================================================================
filter_dates <- function(dat, filt, keep = FALSE){

  if (keep) {

    return(dat[J(filt), on = .(name, datetime >= start, datetime <= end)], list(name, x.datetime, val))

  } else {

    return(dat[!J(filt), on = .(name, datetime >= start, datetime <= end)])

  }

}



#===============================================================================
#' @title shift_values_range
#'
#' @description shift values for specific regions
#'
#' @author Jonathan Kennel \email{[email protected]}
#'
#' @param dat data.table to filter (name, datetime)
#' @param shift data.table of filter start and end times (start, end)
#'
#' @return data.table with shifted values
#'
#' @export
#===============================================================================
shift_values_range <- function(dat, shift){

  dat[J(shift), on = .(name, datetime >= start, datetime <= end), val := val + shift]

}
jkennel/rbr documentation built on July 26, 2017, 6:01 p.m.