Hi,

how can I order the rows and columns of a matrix A to generate B, in order
to minimize the length(rle(B)$lengths) for all the rows and columns ?

> set.seed(5)
> a <- matrix(rnorm(200), nrow=20)
> a[a<=0] <- 0
> a[a>0] <- 1
> a
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    0    1    1    0    1    0    1    0    0     1
 [2,]    1    1    0    1    0    1    1    0    1     0
 [3,]    0    1    0    0    1    1    0    1    1     1
 [4,]    1    1    1    1    0    1    0    1    1     1
 [5,]    1    1    0    0    1    0    1    0    0     0
 [6,]    0    0    1    0    0    1    1    0    0     0
 [7,]    0    1    0    0    1    0    0    1    0     0
 [8,]    0    1    0    0    0    0    1    0    0     0
 [9,]    0    0    0    0    0    0    0    0    0     1
[10,]    1    0    0    0    0    1    0    0    0     0
[11,]    1    1    1    0    1    0    1    1    0     1
[12,]    0    1    1    0    0    1    0    1    1     1
[13,]    0    1    1    1    1    1    0    0    0     0
[14,]    0    1    0    1    1    1    0    1    0     1
[15,]    0    1    0    1    1    0    1    0    0     0
[16,]    0    1    0    0    1    1    1    1    1     1
[17,]    0    0    1    1    0    0    1    0    1     1
[18,]    0    0    0    1    0    1    0    1    0     1
[19,]    1    0    0    1    0    1    1    0    1     0
[20,]    0    0    1    0    0    0    1    1    0     1

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to