title: Replace NA values with preexisting value based on multiple conditions
body: <p>I am working with the following data. It pertains to the dimensions of items and the boxes that they are shipped in.</p>
  <pre><code>       Box_Height     Box_Length     Box_Width Item_Height Item_Length Item_Width
   1             NA             74             4          NA          NA         NA
   2             NA             42            NA           6          42          6
   3              6             NA            NA           6          22          6
   4              6             NA            NA           6          42          6
   5              6             NA            NA           6          42          6
   6             NA             NA            NA          NA          NA         NA
  </code></pre>
  <p>According to the shipment company, when one of the box columns has NA values, it means that the item already comes in a box and is being shipped as is. So, I'd just need to replace the missing Box_Height, for instance, with the Item_Height.</p>
  <p>I wrote the following code to do this:</p>
  <pre><code>df$Box_Height[is.na(df$Box_Height) &amp; !is.na(df$Item_Height)] &lt;- df$Item_Height
  </code></pre>
  <p>I'm ultimately trying to test when a row is missing a box dimension <em>and</em> the specific item dimension is <em>not</em> missing, then replace the missing box dimension with the item dimension.</p>
  <p>I am receiving this error:</p>
  <pre><code>Error in df$Box_Height[is.na(df$Box_Height) &amp;  : 
    NAs are not allowed in subscripted assignments
  </code></pre>
  <p>This is somewhat confusing since that's what I'm trying to replace.</p>
  <p>If anyone has any advice as how to properly do this or where I'm going wrong I'd greatly appreciate the help.</p>