title: Using lapply with if to test each element in a list
body: <p>Suppose I have a list:</p>
  
  <pre><code>alist&lt;- list(4,6,8,9)
  </code></pre>
  
  <p>I want test if each list element is greater than 7 and return a list of 1 if its true and 0 if false.</p>
  
  <p>However I must use lapply.</p>
  
  <pre><code>lapply(alist,if,&gt;7,1) or lapply(alist,if,cond&gt;7,1)
  </code></pre>
  
  <p>Of course none of these work and I keep getting the following error.</p>
  
  <pre><code>Error: unexpected ',' in "lapply(alist, if,"
  </code></pre>