title: Passing data.frame as an argument in function
body: <p><strong>Context</strong></p>
  <p>As a followup to <a href="https://stackoverflow.com/questions/33186633/r-pass-data-frame-by-reference-to-a-function">R: Pass data.frame by reference to a function</a> and <a href="https://stackoverflow.com/questions/6359104/how-to-add-a-column-in-the-data-frame-within-a-function">How to add a column in the data frame within a function</a></p>
  <p>I am attempting the following, seemingly easy, function:</p>
  <pre><code>naToZero &lt;- function(df) {
    df$Vol[is.na(df$Vol)] &lt;- 0
  }
  </code></pre>
  <p>Data.frame</p>
  <pre><code>&gt; str(WFM)
  Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   990571 obs. of  14 variables:
   $ Date      : chr  &quot;04/12/2017&quot; &quot;04/12/2017&quot; &quot;04/12/2017&quot; &quot;04/12/2017&quot; ...
   $ Time      :Classes 'hms', 'difftime'  atomic [1:990571] 41970 41969 41968 41967 41966 ...
    .. ..- attr(*, &quot;units&quot;)= chr &quot;secs&quot;
   $ Bar#      : chr  &quot;197953/197953&quot; NA &quot;197952/197953&quot; NA ...
   $ Bar Index : int  0 NA -1 NA NA -2 NA NA -3 NA ...
   $ Tick Range: int  0 NA 0 NA NA 0 NA NA 0 NA ...
   $ Open      : num  33.9 NA 33.9 NA NA ...
   $ High      : num  33.9 NA 33.9 NA NA ...
   $ Low       : num  33.9 NA 33.9 NA NA ...
   $ Close     : num  33.9 NA 33.9 NA NA ...
   $ Vol       : int  100 NA 200 NA NA 100 NA NA 400 NA ...
   $ MACDHist  : num  -59 NA -87 NA NA ...
   $ MACD      : num  -450 NA -445 NA NA ...
   $ MACDSig   : num  -391 NA -358 NA NA ...
   $ ZScore1   : num  NA NA NA NA NA NA NA NA NA NA ...
  </code></pre>
  <p>Hoping to use this function to speed things up in data cleaning.</p>
  <p><strong>Problem</strong></p>
  <p>After I run the function in the script editor, and then pass a data.frame to run it. But the function does not do anything and when I View(WFM), it's still the same old data. However, when I manually run the command:</p>
  <p><code>WFM$Vol[is.na(WFM$Vol)] &lt;- 0</code></p>
  <p>Then it works.</p>
  <p><strong>Things I tried</strong></p>
  <p>I tried experimenting based on the two links I saw, being seemingly relevant:</p>
  <p>Using <code>WFM &lt;- naToZero(WFM)</code>, produces a vector with a single value, 0.</p>
  <p>Tried using <code>WFM &lt;- data.table(WFM)</code> and running the function... same thing.</p>
  <p>I must be missing something basic.</p>