File: createResample.R

package info (click to toggle)
r-cran-caret 7.0-1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 210; sh: 10; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#' @rdname createDataPartition
#' @export
createResample <- function(y, times = 10, list = TRUE) {
  if (inherits(y, "Surv"))
    y <- y[, "time"]
  trainIndex <- matrix(0, ncol = times, nrow = length(y))
  out <- apply(
    trainIndex, 2,
    function(data) {
      index <- seq(along.with = data)
      out <-
        sort(sample(index, size = length(index), replace = TRUE))
      out
    }
  )

  if (list)  {
    out <- as.data.frame(out, stringsAsFactors = TRUE)
    attributes(out) <- NULL
    names(out) <- prettySeq(out)
  } else {
    colnames(out) <- prettySeq(1:ncol(out))
  }

  out
}