r - Shuffle the columns of a matrix indepently using apply or plyr -


I have a matrix in R, and randomly altering rows without the need to do any loop I want to, but for each column independently

Ie,

  a = cbind (c (1,2,3), c (4,5,6))   < P> And I have to be a new matrix, say excitement, where columns 1c (1,2,3) and column 2c (4,5,6) randomly reshuffle.  

For example,

  asflu = cibind (c (1,3,2), c (6,4,5))   

That is, in column 1, random shuffle changed the position of 2 and 3, and in column 2 a different random shuffle changed the position of 6 to 4, 4 to 5 and 5 to 6.

What would be a good way to do this without requiring a loop in the ROS?

Thank you!

How about it?

  & gt; Apply (A, 2, sample)    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -