[R] Optimization problem, to minimize the length(rle(B)$lengths) for all the rows and columns

From: Ng Stanley <stanleyngkl_at_gmail.com>
Date: Mon, 12 May 2008 21:13:53 +0800


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_at_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. Received on Mon 12 May 2008 - 13:16:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 12 May 2008 - 13:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive