Displaying 1 result from an estimated 1 matches for "shuffle2".
Did you mean:
shuffle
2011 Feb 10
3
Permuting rows of a matrix
Hi,
I need to permute the rows of a matrix, where each row is independently rearranged. A simple solution is this:
shuffled <- datamatrix <- matrix(1:24, ncol = 4)
for (i in 1:nrow(datamatrix)) { shuffled[i, ] <- sample(datamatrix[i, ]) }
> datamatrix
[,1] [,2] [,3] [,4]
[1,] 1 7 13 19
[2,] 2 8 14 20
[3,] 3 9 15 21
[4,] 4 10 16 22
[5,]