utils.R 478 Bytes
Newer Older
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#' partition

#' partition
#' @param dataset list or tibble
#' @param train ratio for training
#' @param test ratio for testing
#' @param seed seed
#' @keywords errorgen
#' @export
#' @examples
#' \dontrun{
#' partition()
#' }
#
partition <- function(dataset,train=0.8,test=0.2,seed=NULL){
  if (!is.null(seed)) set.seed(seed)

  fact <- sample(c("train","test"),dim(dataset)[1],prob=c(train,test),replace=TRUE)
  res <- split(dataset,fact)
  return(res)
}