summaryrefslogtreecommitdiff
path: root/R/preprocess.R
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-08-21 17:59:36 +0530
committerSuraj Yerramilli2015-08-21 17:59:36 +0530
commit136689c0d52c1e4634bf636c10d3e012d566e06d (patch)
tree7cf1ca381607f1eeeeaf01531c27315b4d3c2718 /R/preprocess.R
parentd5add16141ff386d8ec38ea7ff10e836d4340168 (diff)
downloadSysID-R-code-136689c0d52c1e4634bf636c10d3e012d566e06d.tar.gz
SysID-R-code-136689c0d52c1e4634bf636c10d3e012d566e06d.tar.bz2
SysID-R-code-136689c0d52c1e4634bf636c10d3e012d566e06d.zip
Corrected some preprocessing functions
Diffstat (limited to 'R/preprocess.R')
-rw-r--r--R/preprocess.R19
1 files changed, 9 insertions, 10 deletions
diff --git a/R/preprocess.R b/R/preprocess.R
index bbe5f52..17afdb1 100644
--- a/R/preprocess.R
+++ b/R/preprocess.R
@@ -32,7 +32,7 @@ detrend <- function(data,type=c("constant","linear")[1]){
stop("Error: Invalid trend type")
}
- reg <- time(data$output[,1])
+ reg <- time(data)
if(type=="linear"){
formula <- X ~ reg
@@ -99,7 +99,7 @@ predict.detrend <- function(object,newdata=NULL,...){
detrend.predict <- function(object,data){
pred_list <- list()
for(i in 1:ncol(data)){
- pred_list[[i]] <- predict(object[[i]],newdata=data.frame(reg = time(data[,i])))
+ pred_list[[i]] <- predict(object[[i]],newdata=data.frame(reg = time(data)))
}
pred <- data.frame(matrix(unlist(pred_list),ncol=ncol(data),byrow=T))
colnames(pred) <- colnames(data)
@@ -128,18 +128,17 @@ misdata <- function(data){
require(zoo)
f <- function(var,start,end,Ts){
- var <- ts(data=var,start=start,end=end,frequency=floor(1/Ts))
+ var <- ts(data=var,start=start,end=end,frequency=1/Ts)
out <- na.approx(var,na.rm=F)
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)
+ Z <- data
+ outputData(Z) <- apply(outputData(data),2,f,start=time(data)[1],
+ end=tail(time(data),n=1),Ts= data$Ts))
+ inputData(Z) <- apply(inputData(data),2,f,start=time(data)[1],
+ end=tail(time(data),n=1),Ts= data$Ts))
+ Z
}
#' Subset or Resample idframe data