Help formatting data for use with Coin-package cmh_test in R I would like to use the coin package (https://cran.r-project.org/web/packages/coin/coin.pdf) for estimating pvalues from a null distribution together with the cmh_test(,distribution = "approximate"). However, I am unable to correctly format the data to use this function since I already have my data summarized (in the form of a data.frame).  
My data is as follows:
condition   yes_no  replicate   counts 
A   yes 1   429
A   no  1   2919349
B   yes 1   3
B   no  1   2722338
A   yes 2   451
A   no  2   3029471
B   yes 2   1
B   no  2   2592842
A   yes 3   238
A   no  3   2339834
B   yes 3   4
B   no  3   2496848  
Any help would be appreciated.
Thanks,
Ron
 A: Your data:
x = structure(list(condition = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 
2L, 2L, 1L, 1L, 2L, 2L), .Label = c("A", "B"), class = "factor"), 
    yes_no = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L, 1L), .Label = c("no", "yes"), class = "factor"), 
    replicate = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
    3L), counts = c(429L, 2919349L, 3L, 2722338L, 451L, 3029471L, 
    1L, 2592842L, 238L, 2339834L, 4L, 2496848L)), class = "data.frame", row.names = c(NA, 
-12L))

The best way is actually to have the raw data, and do:
table(df$yes_no,df$condition,df$replicate) etc..
Starting with your data, I suppose you want to stratify them according to replicate? Below I would do that, but if you are going to stratifying according to something else, just modify the script:
x = x[order(x$replicate,x$condition,x$yes_no),]
mat=array(x$counts,dim=c(2,2,3),
dimnames=list(levels(x$yes_no),levels(x$condition),levels(x$replicate)))
mat = as.table(mat)

 mat
, , 1

          A       B
no  2919349 2722338
yes     429       3

, , 2

          A       B
no  3029471 2592842
yes     451       1

, , 3

          A       B
no  2339834 2496848
yes     238       4

Then you apply Cochran–Mantel–Haenszel :
cmh_test(mat)

