title: How to Create a Complex Conditional Variable on R
body: <p>I have four binary yes/no variables.
  I want to create a combined variable that is dummy coded in the following manner:</p>
  <ul>
  <li>0 if participants say &quot;Yes&quot; to all 4 Variables (4/4)</li>
  <li>1 if participants say &quot;Yes&quot; to 3 out of the 4 Variables (3/4)</li>
  <li>2 if participants say &quot;Yes to 2 out of the 4 Variables (2/4)</li>
  <li>3 if participants say &quot;Yes&quot; to 1 out of the 4 Variables (1/4)</li>
  <li>4 if participants say &quot;Yes&quot; to 0 out of the 4 Variables (0/4)</li>
  </ul>
  <p>The order of which questions they've said yes to does not matter.</p>
  <p>I've tried to create something like this:</p>
  <pre><code>VariableCodingFor1/4 &lt;- ifelse(Var1 ==&quot;Yes&quot; &amp; Var2 == &quot;No&quot; &amp; Var3 ==&quot;No&quot;, Var4 ==&quot;No&quot;) |
  ifelse(Var1 ==&quot;No&quot; &amp; Var2 == &quot;Yes&quot; &amp; Var3 ==&quot;No&quot;, Var4 ==&quot;No&quot;) |
  ifelse(Var1 ==&quot;No&quot; &amp; Var2 == &quot;No&quot; &amp; Var3 ==&quot;Yes&quot;, Var4 ==&quot;No&quot;) |
  ifelse(Var1 ==&quot;No&quot; &amp; Var2 == &quot;No&quot; &amp; Var3 ==&quot;No&quot;, Var4 ==&quot;Yes&quot;) 
  </code></pre>
  <p>But I'm definitely missing something</p>
  <p>Any help would be greatly appreciated !</p>