R/fillNA_DateTime_sequence.R

Defines functions fillNA_datesequence

Documented in fillNA_datesequence

#' fills DateTime gaps in a timeseries and fills the according values with NA.
#'
#' @param file   a data frame, matrix or array containing one column with POSIXct formated DateTime objects
#' @param timestep   string,  time interval of the input timeseries. Example: "1 min", "10 min", "1 hour"
#' @return returns the file with complete timeseries.
#' @export


fillNA_datesequence <- function(file, timestep)

{
  b <- sapply(file, is.POSIXct)
  c <- unname(which(b == TRUE))
  Time_column <- names(file)[c]
  DateTime <- seq(min(file[, c]), max(file[, c]), by = timestep)
  time_sequence <- as.data.frame(DateTime)
  file <- merge(time_sequence, file, by.x = "DateTime", by.y = Time_column, all.x = TRUE)
  return(file)
}
plvoit/PaulsPack documentation built on Dec. 15, 2019, 10:24 p.m.