summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--R/partition.R57
-rw-r--r--R/preprocess.R64
-rw-r--r--man/dataSlice.Rd6
-rw-r--r--man/detrend.Rd6
4 files changed, 67 insertions, 66 deletions
diff --git a/R/partition.R b/R/partition.R
deleted file mode 100644
index 781209c..0000000
--- a/R/partition.R
+++ /dev/null
@@ -1,57 +0,0 @@
-#' Subset an idframe data
-#'
-#' \code{dataSlice} is a Subsetting method for objects of class \code{idframe}. It
-#' extracts the subset of the object \code{data} observed between indices \code{start}
-#' and \code{end}. If a frequency is specified, the series is then re-sampled at the
-#' new frequency.
-#'
-#' @param data an object of class \code{idframe}
-#' @param start the start index
-#' @param end the end index
-#' @param freq the new sampling frequency
-#'
-#' @details
-#' The dataSlice function extends the \code{\link[stats]{window}} function for idframe
-#' objects
-#'
-#' @return an idframe object
-#'
-#' @examples
-#' data(cstr)
-#' cstrsub <- dataSlice(cstr,start=200,end=400) # extract between indices 200 and 400
-#' cstrTrain <- dataSlice(cstr,end=4500) # extract upto index 4500
-#' cstrTest <- dataSlice(cstr,start=6501) # extract from index 6501 till the end
-#' cstr_new <- dataSlice(cstr,freq=3) # resample data at thrice the frequency
-#'
-#' @seealso \code{\link[stats]{window}}
-#' @export
-dataSlice <- function(data,start=NULL,end=NULL,freq=NULL){
- # check if the class is correct
- if(class(data)!='idframe')
- stop("Not an idframe data")
-
- nin <- dim(data$input)[2]; nout <- dim(data$output)[2]
- dataMatrix <- cbind(data$input,data$output)
- if(data$type=="freq"){
- dataMatrix <- cbind(dataMatrix,data$frequencies)
- } else {
- timeSeq <- seq(from=data$t.start,to=data$t.end,by=data$Ts)
- dataMatrix <- cbind(dataMatrix,timeSeq)
- }
-
- l <- as.list(dataMatrix)
- trimData <- as.data.frame(sapply(l,window,start=start,end=end,deltat=freq))
-
- trim <- idframe(output=trimData[,(nin+1):(nin+nout),drop=F],
- input=trimData[,1:nin,drop=F],type=data$type,Ts=data$Ts,
- tUnit=data$tUnit)
-
- if(trim$type=="freq"){
- trim$frequncies <- trimData[,ncol(trimData)]
- } else {
- trim$t.start <- trimData[1,ncol(trimData)]
- trim$t.end <- trimData[nrow(trimData),ncol(trimData)]
- }
-
- return(trim)
-} \ No newline at end of file
diff --git a/R/preprocess.R b/R/preprocess.R
index 66c4a67..07b0a4a 100644
--- a/R/preprocess.R
+++ b/R/preprocess.R
@@ -1,6 +1,6 @@
-#' Remove linear trends
+#' Remove offsets and linear trends
#'
-#' Removes the mean value or linear trends in each of the input and output matrices.
+#' Removes the offsets or linear trends in each of the input and output matrices.
#'
#' @param data an object of class \code{idframe}
#' @param type trend type - "constant" or "linear". (Default: \code{"linear"})
@@ -21,7 +21,7 @@
#' fit <- detrend(cstr) # remove linear trends
#' Zdetrend <- predict(fit) # get the detrended data
#'
-#' demean <- detrend(cstr,type="constant") # remove mean values
+#' demean <- detrend(cstr,type="constant") # remove offsets
#' Zcent <- predict(demean) # get the centered data
#'
#' @seealso \code{\link{predict.detrend}}, \code{\link[stats]{lm}}
@@ -125,4 +125,62 @@ misdata <- function(data){
end=data$t.end,Ts= data$Ts))
return(dataout)
+}
+
+#' Subset or Resample idframe data
+#'
+#' \code{dataSlice} is a subsetting method for objects of class \code{idframe}. It
+#' extracts the subset of the object \code{data} observed between indices \code{start}
+#' and \code{end}. If a frequency is specified, the series is then re-sampled at the
+#' new frequency.
+#'
+#' @param data an object of class \code{idframe}
+#' @param start the start index
+#' @param end the end index
+#' @param freq the new sampling frequency
+#'
+#' @details
+#' The dataSlice function extends the \code{\link[stats]{window}} function for idframe
+#' objects
+#'
+#' @return an idframe object
+#'
+#' @examples
+#' data(cstr)
+#' cstrsub <- dataSlice(cstr,start=200,end=400) # extract between indices 200 and 400
+#' cstrTrain <- dataSlice(cstr,end=4500) # extract upto index 4500
+#' cstrTest <- dataSlice(cstr,start=6501) # extract from index 6501 till the end
+#' cstr_new <- dataSlice(cstr,freq=3) # resample data at thrice the frequency
+#'
+#' @seealso \code{\link[stats]{window}}
+#' @export
+dataSlice <- function(data,start=NULL,end=NULL,freq=NULL){
+ # check if the class is correct
+ if(class(data)!='idframe')
+ stop("Not an idframe data")
+
+ nin <- dim(data$input)[2]; nout <- dim(data$output)[2]
+ dataMatrix <- cbind(data$input,data$output)
+ if(data$type=="freq"){
+ dataMatrix <- cbind(dataMatrix,data$frequencies)
+ } else {
+ timeSeq <- seq(from=data$t.start,to=data$t.end,by=data$Ts)
+ dataMatrix <- cbind(dataMatrix,timeSeq)
+ }
+
+ l <- as.list(dataMatrix)
+ trimData <- as.data.frame(sapply(l,window,start=start,end=end,deltat=freq))
+
+ trim <- idframe(output=trimData[,(nin+1):(nin+nout),drop=F],
+ input=trimData[,1:nin,drop=F],type=data$type,Ts=data$Ts,
+ tUnit=data$tUnit)
+
+ if(trim$type=="freq"){
+ trim$frequncies <- trimData[,ncol(trimData)]
+ } else {
+ trim$t.start <- trimData[1,ncol(trimData)]
+ trim$t.end <- trimData[nrow(trimData),ncol(trimData)]
+ }
+
+ return(trim)
} \ No newline at end of file
diff --git a/man/dataSlice.Rd b/man/dataSlice.Rd
index 9fd571e..a34e7c6 100644
--- a/man/dataSlice.Rd
+++ b/man/dataSlice.Rd
@@ -1,8 +1,8 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
-% Please edit documentation in R/partition.R
+% Please edit documentation in R/preprocess.R
\name{dataSlice}
\alias{dataSlice}
-\title{Subset an idframe data}
+\title{Subset or Resample idframe data}
\usage{
dataSlice(data, start = NULL, end = NULL, freq = NULL)
}
@@ -19,7 +19,7 @@ dataSlice(data, start = NULL, end = NULL, freq = NULL)
an idframe object
}
\description{
-\code{dataSlice} is a Subsetting method for objects of class \code{idframe}. It
+\code{dataSlice} is a subsetting method for objects of class \code{idframe}. It
extracts the subset of the object \code{data} observed between indices \code{start}
and \code{end}. If a frequency is specified, the series is then re-sampled at the
new frequency.
diff --git a/man/detrend.Rd b/man/detrend.Rd
index 2121ba1..f567247 100644
--- a/man/detrend.Rd
+++ b/man/detrend.Rd
@@ -2,7 +2,7 @@
% Please edit documentation in R/preprocess.R
\name{detrend}
\alias{detrend}
-\title{Remove linear trends}
+\title{Remove offsets and linear trends}
\usage{
detrend(data, type = c("constant", "linear")[2])
}
@@ -23,14 +23,14 @@ A list containing the following elements
}
}
\description{
-Removes the mean value or linear trends in each of the input and output matrices.
+Removes the offsets or linear trends in each of the input and output matrices.
}
\examples{
data(cstr)
fit <- detrend(cstr) # remove linear trends
Zdetrend <- predict(fit) # get the detrended data
-demean <- detrend(cstr,type="constant") # remove mean values
+demean <- detrend(cstr,type="constant") # remove offsets
Zcent <- predict(demean) # get the centered data
}
\seealso{