title: R Looping through in survey package
body: <p>I'm having problems looping through variables using the survey package. Let's say I have a subset of variables I collect into a dataframe together with the survey weight and I want to carry out chi-square tests. Bearing in mind the problems with multiple testing, I would still like to test all unique combinations. This is normally relatively straightforward in R, and there's a good example <a href="https://stackoverflow.com/questions/7382039/chi-square-analysis-using-for-loop-in-r">here</a>.</p>
  
  <p>Unfortunately this become harder in the survey package because items need to be in the design object, and most importantly dataset indexing is not supported (at least as far as I know). I've tried adapting the example mentioned above to svychisq, but all my strategies have failed.</p>
  
  <p>I've noticed that someone has done something similar <a href="https://stackoverflow.com/questions/12573826/looping-through-dataset-variables-in-svy-package">here</a>, but most of the variables are fixed. Would anyone be able to create a function (something similar to <a href="https://stackoverflow.com/questions/7382039/chi-square-analysis-using-for-loop-in-r">this</a> answer maybe) but using the svychisq function? Unfortunately I don't know of datasets with lots of categorical variables and complex design available online. For the purposes of demonstration I suppose one could use dclus1 in data(api) as shown in the function help file and attempt to loop through the first 10 variables</p>
  
  <pre><code>library(survey)
  data(api)
  dclus1&lt;-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  svychisq(~sch.wide+stype, dclus1)
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>UPDATE: What I'm really trying to do is avoiding specifying the variable names and give a vector of variables combinations instead. e.g.</p>
  
  <pre><code>MyChi2tests &lt;- apply( combn(colnames(apiclus1[,c(2,16:17)]),2), 2, function(z) paste(z, collapse = '+')) 
  </code></pre>