Sum per group with a condition in data.table
<p>I wish to sum each group with a condition. I have the following data</p>

<pre><code>a&lt;-data.table (facto=c ("a","b","a","a","b","b","b"), value = c (2,3,2,3,2,2,2))

    facto value
1:     a     2
2:     b     3
3:     a     2
4:     a     3
5:     b     2
6:     b     2
7:     b     2
</code></pre>

<p>and I'd like to compute the sum of facto which their value is not equal to 3 using <code>data.table</code>.</p>

<p>I used this code </p>

<pre><code>output &lt;-a[, (value=sum(value!=3)), .(facto)]
</code></pre>

<p>and it gives me the following data that counts the row which are not equal to 3 for each group:</p>

<pre><code>   facto V1
1:     a  2
2:     b  3
</code></pre>

<p>However, I wish to have the following output:</p>

<pre><code>       facto V1
    1:     a  4
    2:     b  6
</code></pre>