View source: R/sparse_matrix_functions.R
shuffle | R Documentation |
Re-orders the elements in each row or column of the matrix. Useful for defining null distributions. In the case of large sparse matrices (class dgTMatrix
, dgCMatrix
or dgRMatrix
), this is faster than using apply
, although for small matrices it may be slower.
shuffle(mat, MARGIN = 2)
mat |
A matrix. May be sparse (i.e. of class |
MARGIN |
The subscript to apply over. Possible values are |
A matrix of the same size and class as mat
.
mat <- matrix(round(runif(100, max = 100)), 10, 10)
shuffle(mat)
shuffle(mat, MARGIN = 1)
mat[sample(1:100, 80)] <- 0
mat <- as(mat, 'dgCMatrix')
shuffle(mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.