[R] Swap rows and columns in a matrix

David Winsemius dwinsemius at comcast.net
Tue Oct 30 23:51:37 CET 2012

On Oct 30, 2012, at 11:59 AM, Haris Rhrlp wrote:

> Dear R users,
> I want a help to write an algorithm for swapping rows and columns in a matrix

This will "shuffle" columns, although 'randomly permute' is the more common word for this;operation:

mat[, sample(dim(mat)[2] ]

This will swap rows:

mat[ sample(dim(mat)[1],  ]

David Winsemius, MD
Alameda, CA, USA

More information about the R-help mailing list