[R] permutation within rows of a matrix

Juan Antonio Balbuena balbuena at uv.es
Wed Nov 16 17:45:06 CET 2011


Hello
This is probably a basic question but I am quite new to R. 

I need to permute elements within rows of a binary matrix, such as

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    0    0    0    0    1    0    0    0    0     0
 [2,]    0    0    1    1    0    0    0    1    1     0
 [3,]    0    1    0    0    0    0    1    0    0     0
 [4,]    0    0    0    0    0    0    1    1    0     0
 [5,]    0    0    0    1    0    0    0    0    1     0
 [6,]    0    0    1    1    0    0    0    0    0     1
 [7,]    0    0    0    0    0    0    0    0    0     0
 [8,]    1    1    0    1    0    0    0    1    0     1
 [9,]    1    0    0    1    0    1    0    1    0     0
[10,]    0    0    0    0    0    0    0    1    0     1


That is, elements within each row are permuted freely and independently from
the other rows. 

I see that is is workable by creating a array for each row, performing
sample and binding the arrays again, but I wonder whether there is a more
efficient way of doing the trick.

Any help will be much appreciated.



--
View this message in context: http://r.789695.n4.nabble.com/permutation-within-rows-of-a-matrix-tp4076989p4076989.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list