Hi,

Assume a table as below:

    X = 
    
            col1    col2    col3
    row1    "A"      "0"     "1"
    row2    "B"      "2"     "NA"
    row3    "C"      "1"     "2"


I select combinations of two rows, using the code below:

    pair <- apply(X, 2, combn, m=2)

This returns a matrix of the form:

    pair = 
    
         [,1] [,2] [,3]
    [1,] "A"  "0"  "1" 
    [2,] "B"  "2"  NA  
    [3,] "A"  "0"  "1" 
    [4,] "C"  "1"  "2" 
    [5,] "B"  "2"  NA  
    [6,] "C"  "1"  "2"


I wish to iterate over pair, taking two rows at a time, i.e. first isolate `[1,]` and `[2,]`, then `[3,]` and `[4,]` and finally, `[5,]` and `[6,]`. These rows will then be passed as arguments to regression models, i.e. `lm(Y ~ row[i]*row[j])`.

I am dealing with a large dataset. Can anybody advise how to iterate over a matrix two rows at a time, assign those rows to variables and pass as arguments to a function?

Thanks,  
S ;-)

**Edit:** In response to the comments, I should specify that my problem concerns SNP and expression data where I aim to do a pairwise multiple regression analysis (first order regression) in order to assess any possible SNP-SNP interactions that may effect the expression phenotype.
Using `mapply` you can map a function over more than one sequence (list or vector) in one pass e.g. the odd and even rows of a matrix

    fn <- function(i, j) paste("i =", i, "j =", j)
    
    odds <- seq(1, 9, by = 2)
    evens <- odds + 1
    
    mapply(fn, odds, evens)