summaryrefslogtreecommitdiff
path: root/R/preprocess.R
diff options
context:
space:
mode:
authorSuraj Yerramilli2015-08-22 10:07:46 +0530
committerSuraj Yerramilli2015-08-22 10:07:46 +0530
commit7a09475fcde4083d2dbe5d7c21a6a4ae5a1169ec (patch)
tree79c68023451bec4db16d89bf1156a920d96c323e /R/preprocess.R
parentaa21c8e28a2effbddeddce94c6cb0f71af3db388 (diff)
downloadSysID-R-code-7a09475fcde4083d2dbe5d7c21a6a4ae5a1169ec.tar.gz
SysID-R-code-7a09475fcde4083d2dbe5d7c21a6a4ae5a1169ec.tar.bz2
SysID-R-code-7a09475fcde4083d2dbe5d7c21a6a4ae5a1169ec.zip
Modified the dataSlice function to slice by index instead of time
Diffstat (limited to 'R/preprocess.R')
-rw-r--r--R/preprocess.R19
1 files changed, 11 insertions, 8 deletions
diff --git a/R/preprocess.R b/R/preprocess.R
index be3c496..f3df112 100644
--- a/R/preprocess.R
+++ b/R/preprocess.R
@@ -123,6 +123,7 @@ detrend.predict <- function(object,data){
#' summary(cstr_mis) # finding out the number of NAs
#' cstr <- misdata(cstr_mis)
#'
+#' @importFrom zoo na.approx
#' @export
misdata <- function(data){
require(zoo)
@@ -151,8 +152,8 @@ misdata <- function(data){
#' new frequency.
#'
#' @param data an object of class \code{idframe}
-#' @param start the start time of the period of interest
-#' @param end the end time of the period of interes
+#' @param start the start index
+#' @param end the end index
#' @param freq fraction of the original frequency at which the series
#' to be sampled.
#'
@@ -176,15 +177,17 @@ dataSlice <- function(data,start=NULL,end=NULL,freq=NULL){
if(class(data)!='idframe')
stop("Not an idframe data")
+ indexWindow <- function(y,start,end,freq){
+ Y <- as.matrix(y); z <- as.vector(time(y))
+ Y <- window(Y,start=start,end=end,frequency=freq)
+ zw <- window(z,start=start,end=end,frequency=freq)
+ y <- ts(Y,start=zw[1],end=tail(zw,n=1),deltat=diff(zw)[1])
+ }
if(nOutputSeries(data)!=0)
- if(!is.null(freq)) freq*frequency(data)
- outputData(data) <- window(outputData(data),start=start,end=end,
- frequency=freq)
+ outputData(data) <- indexWindow(outputData(data),start,end,freq)
if(nInputSeries(data)!=0)
- if(!is.null(freq)) freq*frequency(data)
- inputData(data) <- window(inputData(data),start=start,end=end,
- frequency=freq)
+ inputData(data) <- indexWindow(inputData(data),start,end,freq)
return(data)
} \ No newline at end of file