title: Applying a function to the whole data table by groups
body: <p>Let's suppose the following data table:</p>
  <pre><code>a = runif(40)
  b = c(rep(NA,5), runif(5), rep(NA,3),runif(3),NA,runif(3), c(rep(NA,3), runif(7), rep(NA,4), runif(3), NA,NA, runif(1)))
  c = rep(1:4,each=10)
  DT = data.table(a,b,c)
  </code></pre>
  <p>I want to eliminate the rows with the first NA values in b for every unique value in c (first NAs when c==1, when c==2...), but not the rows with the NAs that come after.</p>
  <p>I can do it by using a loop:</p>
  <pre><code>for(i in unique(DT$c))
  {
    first_NA = which(DT$c==i)[1]
    last_NA = which(!is.na(DT[,b]) &amp; DT$c==i)[1] - 1
    DT = DT[-c(first_NA:last_NA)]
  }
  </code></pre>
  <p>But I wonder if there is any simpler way of doing this by using a function for the whole data table using groups (by in data table or groupby in dplyr), without just applying it to columns.</p>
  <p>Thank you!</p>