title: R - Saving Variable to dataframe from own function
body: <p>again I'm stuck...</p>
  
  <p>I want to write a function to get several statistics for checking the assumptions for a linear regression. The function I'm quoting is not yet done, but I think you'll get the point:</p>
  
  <pre><code>check.regression &lt;- function(regmodel, dataframe, resplots = TRUE,
                               durbin = TRUE, savecheck = TRUE) {
       print(dwt(regmodel)) # Durbin-Watson-Test
       dataframe$stand.res &lt;- rstandard(regmodel) # Saving Standardized Residuals                   
  }
  </code></pre>
  
  <p>As you see, I want to save the standardized residuals of the model into the given dataframe.</p>
  
  <p>regmodel refers to the model computed by the linear regression lm( y~x) and dataframe is the name of the dataframe from which the regression model is computed.</p>
  
  <p>The problem is: nothing is saved within my function. If I do the command without the function, the residuals are properly saved into my dataframe.</p>
  
  <p>I guess, there has to be something like</p>
  
  <pre><code>save(dataframe$stand.res &lt;- rstandard(regmodel))
  </code></pre>
  
  <p>as I also have to specify plotting or writing things to the console within a function, but I don't know how that command might be.</p>
  
  <p>Any ideas?</p>