summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--R/partition.R33
-rw-r--r--man/dataPartition.Rd21
-rw-r--r--man/dataSlice.Rd17
3 files changed, 69 insertions, 2 deletions
diff --git a/R/partition.R b/R/partition.R
index ffcd44a..0b88f6c 100644
--- a/R/partition.R
+++ b/R/partition.R
@@ -17,6 +17,35 @@ dataSlice <- function(object,indices){
trim$output <- trim$output[indices,]
trim$input <- trim$input[indices,]
- if(trim$type=="freq")
- trim$frequncies <- trim$frequencies[indices]
+ if(trim$type=="freq"){
+ trim$frequncies <- trim$frequencies[indices]
+ } else {
+ trim$t.start <- trim$t.start + Ts*(indices[1]-1)
+ trim$t.end <- trim$t.start + Ts*(length(indices)-1)
+ }
+}
+
+#' Split data into training and validation sets
+#'
+#' The function splits the data into training and validation sets and returns them bundled
+#' as a list. The size of the sets are determined by the parameter \code{p}.
+#'
+#' @param object an object of class \code{idframe}
+#' @param p the percentage of the data that goes to training (Default : \code{0.6})
+#' @return list containing estimation and validation idframe objects
+#' @export
+dataPartition <- function(object,p=0.6){
+ # check if the class is correct
+ if(class(object)!='idframe')
+ stop("Not an idframe object")
+
+ index <- seq_along(object$output[,1])
+
+ trainIndex <- index[1:round(p*length(index))]
+ testIndex <- index[!(index %in% trainIndex)]
+
+ train <- dataSlice(object,trainIndex)
+ test <- dataSlice(object,testIndex)
+
+ return(estimation=train,validation=test)
} \ No newline at end of file
diff --git a/man/dataPartition.Rd b/man/dataPartition.Rd
new file mode 100644
index 0000000..501ace2
--- /dev/null
+++ b/man/dataPartition.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/partition.R
+\name{dataPartition}
+\alias{dataPartition}
+\title{Split data into training and validation sets}
+\usage{
+dataPartition(object, p = 0.6)
+}
+\arguments{
+\item{object}{an object of class \code{idframe}}
+
+\item{p}{the percentage of the data that goes to training (Default : \code{0.6})}
+}
+\value{
+list containing estimation and validation idframe objects
+}
+\description{
+The function splits the data into training and validation sets and returns them bundled
+as a list. The size of the sets are determined by the parameter \code{p}.
+}
+
diff --git a/man/dataSlice.Rd b/man/dataSlice.Rd
new file mode 100644
index 0000000..2489cc3
--- /dev/null
+++ b/man/dataSlice.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2 (4.1.0): do not edit by hand
+% Please edit documentation in R/partition.R
+\name{dataSlice}
+\alias{dataSlice}
+\title{Subset an idframe object}
+\usage{
+dataSlice(object, indices)
+}
+\arguments{
+\item{object}{an object of class \code{idframe}}
+
+\item{indices}{the indices that need to be subsetted}
+}
+\description{
+Subsetting method for objects of class \code{idframe}
+}
+