summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--R/preprocess.R21
1 files changed, 21 insertions, 0 deletions
diff --git a/R/preprocess.R b/R/preprocess.R
index 2c42c90..d01c277 100644
--- a/R/preprocess.R
+++ b/R/preprocess.R
@@ -104,4 +104,25 @@ detrend.predict <- function(object,data){
pred <- data.frame(matrix(unlist(pred_list),ncol=ncol(data),byrow=T))
colnames(pred) <- colnames(data)
return(pred)
+}
+
+#' Replace Missing Data by Interpolation
+#'
+#' @export
+misdata <- function(data){
+ require(zoo)
+
+ f <- function(var,start,end,Ts){
+ var <- ts(data=var,start=start,end=end,frequency=floor(1/Ts))
+ out <- na.approx(var)
+ return(as.numeric(out))
+ }
+
+ dataout <- data
+ dataout$output <- data.frame(apply(data$output,2,f),start=data$t.start,
+ end=data$t.end,Ts= data$Ts)
+ dataout$input <- data.frame(apply(data$input,2,f),start=data$t.start,
+ end=data$t.end,Ts= data$Ts)
+
+ return(dataout)
} \ No newline at end of file