title: reset cell values based on values in another column in R
body: <p>I have a data frame which resembles the table given below.</p>
  
  <pre><code>  sponbrand aidbrand
  1      &lt;NA&gt;     LAYS
  2      &lt;NA&gt;     LAYS
  3      &lt;NA&gt;     &lt;NA&gt;
  4      &lt;NA&gt;     LAYS
  5      LAYS     LAYS
  6      &lt;NA&gt;     &lt;NA&gt;
  </code></pre>
  
  <p>The reproducible format is as follows:</p>
  
  <pre><code>structure(list(sponbrand = c(NA, NA, NA, NA, "LAYS", NA), aidbrand = c("LAYS", 
  "LAYS", NA, "LAYS", "LAYS", NA)), .Names = c("sponbrand", 
  "aidbrand"), row.names = c(NA, 6L), class = "data.frame")
  </code></pre>
  
  <p>I am trying to set the following:</p>
  
  <p>If I have a brand in sponbrand I am trying to set the corresponding row in aidbrand as NA.  In the above example, row number 5, has Lays in it in the column sponbrand.  I have Lays in aidbrand column too in row number 5, which I want to set to NA while retaining the rest of the brands in aid brand.  The desired output is as follows:</p>
  
  <pre><code>  sponbrand aidbrand
  1      &lt;NA&gt;     LAYS
  2      &lt;NA&gt;     LAYS
  3      &lt;NA&gt;     &lt;NA&gt;
  4      &lt;NA&gt;     LAYS
  5      LAYS     NA ----&gt;&gt; This is the row I want to reset, while retaining the rest.
  6      &lt;NA&gt;     &lt;NA&gt;
  </code></pre>
  
  <p>I have used the following code: cc is my df:</p>
  
  <pre><code>if("aidbrand" %in% colnames(cc)){cc$aidbrand &lt;- ifelse(cc$sponbrand == "LAYERR", NA, cc$aidbrand)}
  </code></pre>
  
  <p>This code works perfectly when I have cells without NA's in sponbrand.  However with the current data set this code sets every cell in aidbrand as NA, whereas I want to retain the brands that already exists in aidbrand column.</p>