[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] randomly permuting rows or col's of a matrix
From:       Barry Rowlingson <B.Rowlingson () lancaster ! ac ! uk>
Date:       2003-11-25 10:38:03
[Download RAW message or body]

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic