title: Sampling out of tables depending on other variables (R)
body: <p>I am a physician just who just started working in R and appreciate any help in this question:
  i have 2 tables (A, B) with the variables age (continous), sex (binary) and test_value (binary). Each table has a different age and sex distribution.</p>
  
  <pre><code>set.seed(10)
  AgeA &lt;- round(rnorm(100, mean = 40, sd = 15))
  SexA &lt;- sample(c("M","F"), 100, replace = TRUE, prob = c(0.5, 0.5))
  Test_ValueA &lt;- rbinom(100, 1, 0.3)
  
  set.seed(20)
  AgeB &lt;- round(rnorm(1000, mean = 50, sd = 15))
  SexB &lt;- sample(c("M","F"), 1000, replace = TRUE, prob = c(0.5, 0.5))
  Test_ValueB &lt;- rbinom(1000, 1, 0.4)
  
  A &lt;- data.frame(Age = AgeA, Sex = SexA, Test = Test_ValueA)
  B &lt;- data.frame(Age = AgeB, Sex = SexB, Test = Test_ValueB)
  
  genderA&lt;-(prop.table(table(A[,2])))
  TestA&lt;-(prop.table(table(A[,3])))
  paste("median age in group A is",median(A[,1]), "percentage female in group A is",genderA[1], "percentage of test positive in A is", TestA[2])
  
  genderB&lt;-(prop.table(table(B[,2])))
  TestB&lt;-(prop.table(table(B[,3])))
  paste("median age in group A is",median(B[,1]), "percentage female in group B is",genderB[1], "percentage of test positive in A is", TestB[2])
  </code></pre>
  
  <p>The difference in test-proportion is now confounded by age and sex.
  now i would like to match the patients from table A with table B to adjust for age and sex. because B is the smaller cohort i would prefer to sample out of A and match to B. is the match package an option? any other ideas</p>
  
  <p>hopefully I was able to explain my problem.
  any hints to which functions this may point?</p>