title: R: mutate() with apply after select() using chaining
body: <pre><code>require('dplyr')
  set.seed(8)
  df &lt;- data.frame(v1=rnorm(5),
                   v2=rnorm(5),
                   v3=rnorm(5))
  </code></pre>
  
  <p>If I which to count the number of values above, say, 0 and put this in an new column I would do:</p>
  
  <pre><code>mutate(df, n=apply(df,1,function(x)sum(x&gt;0)))
  </code></pre>
  
  <p>This would give:</p>
  
  <pre><code>       v1         v2          v3 n
  1 -0.08458607 -0.1078814 -0.75979380 0
  2  0.84040013 -0.1702891  0.29204986 2
  3 -0.46348277 -1.0883317  0.42139859 1
  4 -0.55083500 -3.0110517 -1.29448908 0
  5  0.73604043 -0.5931743  0.06928509 2
  </code></pre>
  
  <p>Now I want to use <code>dplyr</code>with chaining and make the same thing on a subset of columns,<code>v1</code>  and <code>v2</code>, but cannot figure out how to give apply the right data. If I just do (after making <code>df</code> again of cause):</p>
  
  <pre><code>df %&gt;%
     select(v1, v2) %&gt;%
     mutate(n=apply(df,1,function(x)sum(x&gt;0)))
  </code></pre>
  
  <p>...Gives the same as above (same <code>n</code>i.e. it counts across all three columns), while passing data with <code>.</code>or just blank: Does not work.</p>
  
  <pre><code>df %&gt;%
     select(v1, v2) %&gt;%
     mutate(n=apply(.,1,function(x)sum(x&gt;0)))
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>df %&gt;%
     select(v1, v2) %&gt;%
     mutate(n=apply(1,function(x)sum(x&gt;0)))
  </code></pre>
  
  <p>Whats wrong?</p>