title: Transformation of missing values by taking log(x+1)
body: <p>I am trying to learn R and I have a data frame which contains 68 continuous and categorical variables. There are two variables  -> x and lnx, on which I need help. Corresponding to a large number of 0's &amp; NA's in x, lnx shows NA. Now, I want to write a code through which I can take log(x+1) in order to replace those NA's in lnx to 0, where corresponding x is also 0 (if x == 0, then I want only lnx == 0, if x == NA, I want lnx == NA). Data frame looks something like this - </p>
  
  <pre><code>  a       b       c       d       e      f         x        lnx
  AB1001   1.00    3.00    67.00   13.90   2.63    1776.7     7.48
  AB1002   0.00    2.00    72.00   38.70   3.66    0.00       NA
  AB1003   1.00    3.00    48.00   4.15    1.42    1917       7.56
  AB1004   0.00    1.00    70.00   34.80   3.55    NA         NA
  AB1005   1.00    1.00    34.00   3.45    1.24    3165.45    8.06
  AB1006   1.00    1.00    14.00   7.30    1.99    NA         NA
  AB1007   0.00    3.00    53.00   11.20   2.42    0.00       NA
  </code></pre>
  
  <p>I tried writing the following code - </p>
  
  <pre><code>data.frame$lnx[is.na(data.frame$lnx)] &lt;-  log(data.frame$x +1)
  </code></pre>
  
  <p>but I get the following warning message and the output is wrong: </p>
  
  <p>number of items to replace is not a multiple of replacement length. Can someone guide me please.</p>
  
  <p>Thanks.</p>