title: How to crosstabulate the missings with data.table
body: <p>Say we have this toy example:</p>
  
  <pre><code>prueba &lt;- data.table(aa=1:7,bb=c(1,2,NA, NA, 3,1,1),
  cc=c(1,2,NA, NA, 3,1,1) , YEAR=c(1,1,1,2,2,2,2))
  
     aa bb cc YEAR
  1:  1  1  1    1
  2:  2  2  2    1
  3:  3 NA NA    1
  4:  4 NA NA    2
  5:  5  3  3    2
  6:  6  1  1    2
  7:  7  1  1    2
  </code></pre>
  
  <p>I want to create a table with the values of something by YEAR.
  In this simple example I will just ask for the table that says how many missing and non-missing I have.</p>
  
  <p>This is an ugly way to do it, specifying everything by hand:   </p>
  
  <pre><code>prueba[,.(sum(is.na(.SD)),sum(!is.na(.SD))), by=YEAR]
  </code></pre>
  
  <p>Though it doesn't label automatically the new columns we see it says I have 2 missings and 7 non-missing values for year 1, and ...</p>
  
  <pre><code>   YEAR V1 V2
  1:    1  2  7
  2:    2  2 10
  </code></pre>
  
  <p>It works but what I would really like is to be able to use table() or some data.table equivalent command instead of specifying by hand every term. That would be much more efficient if I have many of them or if we don't know them beforehand.</p>
  
  <p>I've tried with: </p>
  
  <pre><code>prueba[,table(is.na(.SD)), by=YEAR]
  </code></pre>
  
  <p>but it doesn't work, I get this:</p>
  
  <pre><code>   YEAR V1
  1:    1  7
  2:    1  2
  3:    2 10
  4:    2  2
  </code></pre>
  
  <p>How can I get the same format than above?<br>
  I've unluckily tried by using as.datable, unlist, lapply, and other things. I think some people use dcast but I don't know how to use it here.<br>
  Is there a simple way to do it?
  My real table is very large.
  Is it better to use the names of the columns instead of .SD?</p>