title: apply custom function to columns in R
body: <p>Here is my code, I expect it to insert zero into second place of every column, but it does not work. </p>
  
  <pre><code>insert_zero &lt;- function(smpl_vec){
    return(smpl_vec[2]&lt;-0)
  }
  
  my_df = data.frame('col_1'= c(1,2,3), 'col_2'= c(2,3,4))
  apply(my_df, 2, insert_zero)
  </code></pre>
  
  <p>How can I fix  it?</p>
  
  <p>P.S. This is just simplified example. Actual function is more complicated.</p>