# [R] Help on a matrix task

Serguei Kaniovski kaniovsk at wsr.ac.at
Tue Dec 6 11:43:06 CET 2005

```Hello,

Being new to R, I am completely stuck with the following problem. Please
help to find a general solution to the following matrix task:
Given:

N<-4

input_mat<-matrix(c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),ncol=N)

combin_mat<-matrix(c(1, 2,
1, 3,
1, 4,
2, 3,
2, 4,
3, 4),ncol=choose(N,2))

Find the indices of rows in "input_mat", whose elements indicated by the
pair of elements in each column of "combin_mat", are equal 1. So, for
the first
column of combin_mat (1,2) the answer should be 1,2,3, and 4th row of
"input_mat" has 1 as the first and second element, for the secondcolumn
of combin_mat (1,3) the answer should be 1,2,5,6, for the third column
of combin_mat (1,4) the answer should be 1,3,5,7, an so on.

"input_mat" is the matrix of binary representations of the first 2^N-1
decimals in the descending order, here N=4, so 7,6,...,0. "combin_mat"
is the matrix of all combinations of N by 2.

```