shuffle_rows: Shuffle along the first dimension multiple arrays in sync

Description Usage Arguments Value Examples

View source: R/shuffle.R

Description

Shuffle along the first dimension multiple arrays in sync

Usage

1

Arguments

...

arrays of various dimensions (vectors and data.frames OK too)

Value

A list of objects passed on to ..., or if a single object was supplied, then the single object shuffled

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
x <- 1:3
y <- matrix(1:9, ncol = 3)
z <- array(1:27, c(3,3,3))

if(require(zeallot)) {
  c(xs, ys, zs) %<-% shuffle_rows(x, y, z)

  l <- lapply(seq_along_rows(y), function(r) {
    list(x = x[r], y = y[r,], z = z[r,,])
  })

  ls <- lapply(seq_along_rows(y), function(r) {
    list(x = xs[r], y = ys[r,], z = zs[r,,])
  })

  stopifnot(
    length(unique(c(l, ls))) == length(l))
}

listarrays documentation built on March 26, 2020, 6:10 p.m.