[R] randomly permuting rows or col's of a matrix
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Tue Nov 25 11:38:03 CET 2003
Pascal A. Niklaus wrote:
> Is there an shortcut (compared to "manually" swap row vectors) for the
> random permutation of rows of a matrix?
>
> "sample" does not act on the element row vectors as a whole.
>
True, but sample(nrow(foo)) gives you a permutation of 1:nrow(foo)
that you can subscript with:
foo[sample(nrow(foo)),]
or
foo[,sample(ncol(foo))]
Baz
More information about the R-help
mailing list