sampleAcross | R Documentation |
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.
sampleAcross(..., by = NULL, replace = FALSE)
... |
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 |
replace |
Logical. If |
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).
sample
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.