title: Creating a subset based on the branching logic
body: <p>I need to include or exclude the variable from a data set based on the factor variable (branching logic).
  If var 1 = 1 then include var2 and var3, otherwise exclude.
  I tried:</p>
  <pre><code>Newdf&lt;- ifelse((var1 == &quot;1&quot;,c(var2),c(-var2)) ,
  ifelse((var1 == &quot;1&quot;,c(var3),c(-var3))
  </code></pre>
  <p>And with dplyr:</p>
  <pre><code>Newdf&lt;- df %&gt;%
  select( if_else(var1== 1,var2,-var2))%&gt;%
  select( if_else(var1== 1,var3,-var3))
  </code></pre>
  <p>Thank you for your help.</p>