title: Subtract value from each list's element in R
body: <p>I need to subtract specified value from each list element in R. In <a href="https://nsaunders.wordpress.com/2010/08/20/a-brief-introduction-to-apply-in-r/" rel="noreferrer">this</a> article is mentioned that for such tasks the <code>apply</code> family of functions are used instead of loops. I've tried following:</p>
  
  <pre><code># Define list
  &gt; a = 1:20
  
  # Substraact this from each element
  &gt; substract_me = 5
  
  # Function for substracting
  &gt; substract = function(x,y) { ret = x-y; return(ret) }
  
  # The problem is that I do not know how to access the current array element and pass it to substract function
  lapply(a, substract)
  </code></pre>
  
  <p><a href="https://rollingyours.wordpress.com/category/r-programming-apply-lapply-tapply/" rel="noreferrer">Here</a> is mentioned that the anonymous functions can be also used, but it did not worked for me and I get syntax error. Indeed it looks to me just like syntactic sugar. The problem remain the same, that I need some placeholder or something when I am using <code>lapply</code> function so I can access the current list element:</p>
  
  <pre><code>lapply(a, function([WHAT TO ADD HERE???],substract_me) substract([WHAT TO ADD HERE???],substract_me))
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/6253159/using-lapply-with-changing-arguments">Here</a> is something probably related but I did not figure out how stuff works from posted code snippets.</p>