title: Using lapply function on svychisq
body: <p>I have a dataset named &quot;drugs&quot; and I created a weighted dataset named &quot;weighted_data&quot;.</p>
  <pre><code>weighted_data &lt;- svydesign(id = ~cluster, 
                             strata = ~strata, 
                             weights = ~weights, 
                             data = drugs, 
                             nest = TRUE)
  </code></pre>
  <p>I can use this function to perform a chi-squared test on all the variables to see if the proportions in states with medical marijuana laws are significantly different from states without medical marijuana laws.</p>
  <pre><code>svychisq(~religion_importance + medmj_law, design=weighted_data)
  </code></pre>
  <p>Naturally, I don't want to do this for all 12 variables, so I want to use an lapply function.</p>
  <pre><code>lapply(names(drugs[-c(1, 14:16)]), function(x)
    svychisq(
      as.formula(bquote(~.(as.name(x))) + medmj_law ), 
      design = weighted_data))
  </code></pre>
  <p>But I keep getting <em>&quot;Error in as.formula(bquote(~.(as.name(x))) + medmj_law) : object 'medmj_law' not found&quot;</em>. Something must be wrong with my syntax.</p>
  <p>For reference, the first variable is &quot;medmj_law&quot; and variables 2-13 are the 12 categorical variables I want to do chi-squared tests on. And I used this code to calculate proportions, which works.</p>
  <pre><code>overall_table_weighted &lt;- lapply(names(drugs[,-c(14:16)]), function(x)
    svytable(bquote(~.(as.name(x))), design=weighted_data))
  
  overall_prop_weighted &lt;- lapply(names(drugs[,-c(14:16)]), function(x)
    round(prop.table(svytable(bquote(~.(as.name(x))), design=weighted_data))*100, 2))
  </code></pre>