title: Flag each record by comparing two variables in R
body: <p>How do I create a new binary variable that compares two other binary variables in an existing data frame?</p>
  
  <p>For the data frame "dframe":</p>
  
  <pre><code>    ID       FlagA  FlagB
  1   28602363    1    0
  2   28605734    0    1
  3   28608629    1    0
  4   28611734    1    0
  5   28619822    NA   0
  6   28622689    1    1
  7   28650295    NA   1
  8   28650378    0    1
  9   28651602    1    1
  10  28656060    1    0
  </code></pre>
  
  <p>I tried to create the column "FlagAB", which would be 1 if FlagA=1 and FlagB=0, and 0 for any other combination, like this:</p>
  
  <pre><code>    ID          FlagA   FlagB   FlagAB
  1   28602363    1       0       1
  2   28605734    0       1       0
  3   28608629    1       0       1
  4   28611734.71 1       0       1
  5   28619822    NA      0       0
  6   28622689.71 1       1       0
  7   28650295    NA      1       0
  8   28650378    0       1       0
  9   28651602    1       1       0
  10  28656060    1       0       0
  </code></pre>
  
  <p>I tried a few variations of the following with no luck. This one populates all rows of FlagAB with "0"</p>
  
  <pre><code>dframe$FlagAB &lt;- ifelse((dframe$FlagA=="1")&amp;(dframe$FlagB=="0"),1,0)
  </code></pre>