title: Error in `$<-.data.frame`(`*tmp*`, newvar, value = numeric(0)) : replacement has 0 rows, data has 139
body: <p>Can anyone tell me why my function won't work? Everything works when it is not in a function. Please see below:</p>
  
  <pre><code>scale.it&lt;-function(df,var,newvar){
  
    varn &lt;- as.numeric(df$var)
  
    last &lt;- max(varn)
  
    df$newvar &lt;- (varn/last)
  
    return(df)
  }
  
  scale.it(go.cubs.go,PAge,IPAge)
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>Error in `$&lt;-.data.frame`(`*tmp*`, newvar, value = numeric(0)) : replacement 
  has 0 rows, data has 139
  </code></pre>