title: How to create 2-way contingency tables in R
body: <p>(Disclaimer: With apologies, I did ask a similar question previously. It did not get any answer, and it was closed.)</p>
  <p>I would like to create 2-way contingency tables of different sizes, say, from 3x3 to 10x15, where some should show significant association (using <code>chisq.test()</code> or similar) and some don't. I've ran to bits-and-peaces of potentially relevant posts, but I do not see the way to connect all the dots. For example, there is <a href="https://stackoverflow.com/questions/948327/efficient-way-to-generate-random-contingency-tables">this post</a> that discusses how to create random 2-way tables with <code>r2dtable()</code>. Next, there are posts about generating random integers that sum-up to a particular value, <a href="https://stackoverflow.com/questions/24845909/generate-n-random-integers-that-sum-to-m-in-r">here</a> and <a href="https://stackoverflow.com/questions/52559455/generate-non-negative-or-positive-random-integers-that-sum-to-a-fixed-value">here</a>, which could be useful to define row and column marginals for <code>r2dtable()</code>.</p>
  <p>Nevertheless, it escapes me how to generate a list of such tables. Also, it seems that <code>r2dtable()</code> always return tables that show no association. I suppose this is to be expected given that the tables are random.</p>
  <p>Can anyone help, please?</p>