count positive negative values in column by group
<p>I want to create two variables giving me the total number of positive and negative values by id, hopefully using <code>dplyr</code>.</p>

<p>Example data:</p>

<pre><code>library(dplyr)    
set.seed(42)
    df &lt;- data.frame (id=rep(1:10,each=10),
                      ff=rnorm(100, 0,14 ))
&gt; head(df,20)
   id          ff
1   1  19.1934183
2   1  -7.9057744
3   1   5.0837978
4   1   8.8600765
5   1   5.6597565
6   1  -1.4857432
7   1  21.1613080
8   1  -1.3252265
9   1  28.2579320
10  1  -0.8779974
11  2  18.2681752
12  2  32.0130355
13  2 -19.4440498
14  2  -3.9030427
15  2  -1.8664987
16  2   8.9033056
17  2  -3.9795409
18  2 -37.1903759
19  2 -34.1665370
20  2  18.4815868
</code></pre>

<p>the resulting dataset should look like:</p>

<pre><code>&gt; head(df,20)
   id          ff pos neg
1   1  19.1934183   6   4
2   1  -7.9057744   6   4
3   1   5.0837978   6   4
4   1   8.8600765   6   4
5   1   5.6597565   6   4
6   1  -1.4857432   6   4
7   1  21.1613080   6   4
8   1  -1.3252265   6   4
9   1  28.2579320   6   4
10  1  -0.8779974   6   4
11  2  18.2681752   4   6
12  2  32.0130355   4   6
13  2 -19.4440498   4   6
14  2  -3.9030427   4   6
15  2  -1.8664987   4   6
16  2   8.9033056   4   6
17  2  -3.9795409   4   6
18  2 -37.1903759   4   6
19  2 -34.1665370   4   6
20  2  18.4815868   4   6
</code></pre>

<p>I have thought something similar to this will work:</p>

<pre><code>df&lt;-df%&gt;% group_by(id) %&gt;%  mutate(pos= nrow(ff&gt;0)) %&gt;% ungroup()
</code></pre>

<p>Any help would be great, thanks.</p>