R/4_3_1Imputing_1NA.R

Defines functions imp_1NA

Documented in imp_1NA

#' @title Imputing gaps of size 1
#' @description Imputes isolated missing values based on the average of nearest neighbours.
#' @param data a univariate signal
#' @param pos1 the position of the begining of gaps of size 1, as obtained using Indexes_size_missing_multi() function
#' @return A new vector of the same size with imputed values.

imp_1NA<-function(data, pos1){
  N <- length(data)
  begin <- sapply(pos1, function(x){max(1, x-1)})
  end <- sapply(pos1, function(x){min(N, (x+1))})
  imp_value1 <- rowMeans(cbind(data[begin], data[end]), na.rm=TRUE)
  data_out <- data
  data_out[pos1] <- imp_value1
  return(data_out)
}

Try the DTWUMI package in your browser

Any scripts or data that you put into this service are public.

DTWUMI documentation built on Sept. 9, 2026, 9:08 a.m.