Re: [R] Help on a matrix task

From: JeeBee <JeeBee_at_troefpunt.nl>
Date: Tue 06 Dec 2005 - 23:41:05 EST

Here is one possible solution:

for(cr in seq(1, dim(combin_mat)[2])) {
  W = which(input_mat[,combin_mat[1,cr]] == 1 &

            input_mat[,combin_mat[2,cr]] == 1)   cat("Combination", cr, "(", combin_mat[,cr], ") :", W, "\n")
}

JeeBee.

---
Full program:

N = 4

input_numbers = seq((2^N)-1, 0, -1)
# convert to binary matrix
input_mat = NULL
for(i in seq(N-1,0,-1)) {
  new_col = input_numbers %% 2
  input_mat = cbind(new_col, input_mat)
  input_numbers = (input_numbers - new_col) / 2

}
colnames(input_mat) = NULL library(gtools) combin_mat = t(combinations(n=N, r=2, v=1:N, set=TRUE, repeats.allowed=FALSE)) for(cr in seq(1, dim(combin_mat)[2])) { W = which(input_mat[,combin_mat[1,cr]] == 1 & input_mat[,combin_mat[2,cr]] == 1) cat("Combination", cr, "(", combin_mat[,cr], ") :", W, "\n")
}
______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Dec 07 00:03:28 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:41:29 EST