csplit: Split data into folds

Description Usage Arguments Author(s) Examples

View source: R/csplit.R

Description

Split data into folds

Usage

1
csplit(x, p = NULL, replace = FALSE, return.index = FALSE, k = 2, ...)

Arguments

x

Data or integer (size)

p

Number of folds, or if a number between 0 and 1 is given two folds of size p and (1-p) will be returned

replace

With or with-out replacement

return.index

If TRUE index of folds are returned otherwise the actual data splits are returned (default)

k

(Optional, only used when p=NULL) number of folds without shuffling

...

additional arguments to lower-level functions

Author(s)

Klaus K. Holst

Examples

1
2
3
4
foldr(5,2,rep=2)
csplit(10,3)
csplit(iris[1:10,]) ## Split in two sets 1:(n/2) and (n/2+1):n
csplit(iris[1:10,],0.5)

Example output

[[1]]
[[1]]$`1`
[1] 4 1 3

[[1]]$`2`
[1] 2 5


[[2]]
[[2]]$`1`
[1] 3 2 5

[[2]]$`2`
[1] 4 1


$`1`
[1] 6 9 5 3

$`2`
[1] 10  1  7

$`3`
[1] 4 8 2

$`1`
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa

$`2`
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
6           5.4         3.9          1.7         0.4  setosa
7           4.6         3.4          1.4         0.3  setosa
8           5.0         3.4          1.5         0.2  setosa
9           4.4         2.9          1.4         0.2  setosa
10          4.9         3.1          1.5         0.1  setosa

[[1]]
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
7          4.6         3.4          1.4         0.3  setosa
3          4.7         3.2          1.3         0.2  setosa
9          4.4         2.9          1.4         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa

[[2]]
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
8           5.0         3.4          1.5         0.2  setosa
6           5.4         3.9          1.7         0.4  setosa
10          4.9         3.1          1.5         0.1  setosa
5           5.0         3.6          1.4         0.2  setosa
1           5.1         3.5          1.4         0.2  setosa

lava documentation built on Sept. 5, 2021, 5:43 p.m.