title: Why add column data to data frame not working with a function in r
body: <p>I am curious that why the following code doesn't work for adding column data to a data frame.</p>
  
  <pre><code>a &lt;- c(1:3)
  b &lt;- c(4:6)
  df &lt;- data.frame(a,b)  # create a data frame example
  
  add &lt;- function(df, vector){
      df[[3]] &lt;- vector
  }                     # create a function to add column data to a data frame
  
  d &lt;- c(7:9)           # a new vector to be added to the data frame
  add(df,d)             # execute the function
  </code></pre>
  
  <p>If you run the code in R, the new vector doesn't add to the data frame and no error also.</p>