title: trouble getting Lapply with on-the-fly function to run correctly
body: <p>I am trying to work with lapply function using a dataframe based on a binary variable in the 5th column. </p>
  
  <p>The function I made is pretty straight forward. a simple t.test and works quite well</p>
  
  <pre><code>t.test.by.ind = function(x, ind) {
    stopifnot(all(ind %in% c(0, 1)))
    return(t.test(x[ind == 0], x[ind == 1]))
  }
  </code></pre>
  
  <p>now, to the problem, I cannot for the life of me get lapply working. I've tried several variants such as: </p>
  
  <pre><code>##Note that pros.dat = my dataframe
  
  lapply(pros.dat, FUN = function(df){
    return(apply(pros.dat[,-5], MARGIN = 2, 
        FUN = t.test.by.ind, ind = pros.dat[,5]))
  })
  </code></pre>
  
  <p>and</p>
  
  <pre><code>##Note that pros.dat = my dataframe
  
  lapply(pros.dat, FUN = function(df){
    return(apply(df[,-5], MARGIN = 2, 
        FUN = t.test.by.ind, ind = df[,5]))
  })
  
  </code></pre>
  
  <p>I have the worst time trying to get lapply to work. I can get apply working just fine. </p>
  
  <pre><code>apply(pros.dat[,-5], MARGIN = 2, FUN = t.test.by.ind, ind = pros.dat[,5])
  </code></pre>
  
  <p>Why can't I see what I'm doing wrong? </p>