summaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-06-05 12:28:43 +0530
committerSuraj Yerramilli2015-06-05 12:28:43 +0530
commit169ab9e7286e0ce2a90e9a05c8015ac8679113ff (patch)
treebf68d48015496f20c6b4dfcce8031b33932f5222 /R
parent8992494aed39a15fee2ab9e6212673168169805d (diff)
downloadSysID-R-code-169ab9e7286e0ce2a90e9a05c8015ac8679113ff.tar.gz
SysID-R-code-169ab9e7286e0ce2a90e9a05c8015ac8679113ff.tar.bz2
SysID-R-code-169ab9e7286e0ce2a90e9a05c8015ac8679113ff.zip
Added function for replacing missing data
Diffstat (limited to 'R')
-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