sampleAcross {statisfactory}R Documentation

Permute values across two vectors or columns in two data frames or matrices

Description

This function permutes values across two or more vectors or columns between two or more data frames or matrices. If vectors, then all values are swapped randomly and the output is a list object with vectors of the same length. If data frames or matrices, then values in selected columns are swapped across the data frames or matrices and the output is a list object with data frames or matrices of the same dimension as the originals.

Usage

sampleAcross(..., by = NULL, replace = FALSE)

Arguments

...

One or more vectors, data frames, or matrices (all objects must be the same class).

by

Character list or list of integers. Names of columns or column numbers to permute (only used if ... is data frames or matrices). If left as NULL (default) the all columns are permuted.

replace

Logical. If TRUE then sample with replacement. If FALSE (default) then sample without replacement.

Value

A list object with same number of elements as in ... with the original dimensions. The order is the same as in ... (e.g., so if the call is like sampleAcross(a, b, c) then the output will be a list with permuted versions of a, b, and c in that order).

See Also

sample

Examples


x1 <- 1:5
x2 <- 6:10
x3 <- 50:60
sampleAcross(x1, x2, x3)
sampleAcross(x1, x2, x3, replace=TRUE)

a <- data.frame(x=1:10, y=letters[1:10])
b <- data.frame(x=11:20, y=letters[11:20])
sampleAcross(a, b, by='y')
sampleAcross(a, b)


[Package statisfactory version 1.0.4 Index]