title: Summarise values dplyr r
body: <p>I have a target variable ranging from -33 to 17 and the variable merchant_category_id that has int type.</p>
  
  <pre><code>summary(total_trans$target)
       Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
  -33.21928  -0.80808  -0.09018  -0.45554   0.54223  17.96507 
  
  str(total_trans$merchant_category_id)
  merchant_category_id: int  278 307 705 307 705 307 705 307 278 332
  </code></pre>
  
  <p>I want to find the quantity, from lowest to highest, of the variable merchant_category_id, only when the target variable is less than or equal to the first quartile.</p>
  
  <p>I tried to do this:</p>
  
  <pre><code>total_trans %&gt;% group_by(merchant_category_id) %&gt;% summarise(counting = count(merchant_category_id))
  </code></pre>
  
  <p>Response is an error:</p>
  
  <pre><code>Error in summarise_impl(.data, dots) : 
    Evaluation error
  </code></pre>
  
  <p>After:</p>
  
  <pre><code>total_trans %&gt;% summarise(Range = list(range(merchant_category_id[target &lt;= summary(target)[2]])))
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code>    Range
  1 -1, 891
  </code></pre>
  
  <p>Also try:</p>
  
  <pre><code>total_trans %&gt;% group_by(merchant_category_id) %&gt;% summarise(Range = list(range(target[target &lt; -0.80808])))
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code># A tibble: 325 x 2
     merchant_category_id Range    
                    &lt;int&gt; &lt;list&gt;   
   1                   -1 &lt;dbl [2]&gt;
   2                    2 &lt;dbl [2]&gt;
   3                    9 &lt;dbl [2]&gt;
   4                   11 &lt;dbl [2]&gt;
   5                   14 &lt;dbl [2]&gt;
   6                   16 &lt;dbl [2]&gt;
   7                   18 &lt;dbl [2]&gt;
   8                   19 &lt;dbl [2]&gt;
   9                   21 &lt;dbl [2]&gt;
  10                   27 &lt;dbl [2]&gt;
  # ... with 315 more rows
  There were 26 warnings (use warnings() to see them)
  </code></pre>
  
  <p>If I do this</p>
  
  <pre><code>total_trans %&gt;% count(merchant_category_id, wt = target &lt; -0.80808)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>total_trans %&gt;%
    mutate(q1 = target &lt;= quantile(target, 1/4)) %&gt;%
    filter(q1) %&gt;%
    group_by(merchant_category_id) %&gt;%
    summarise(count = n())
  </code></pre>
  
  <p>I get this in response:</p>
  
  <pre><code>   merchant_category_id     n
                    &lt;int&gt; &lt;int&gt;
   1                   -1   432
   2                    2  8364
   3                    9  2580
   4                   11     9
   5                   14  1800
   6                   16   177
   7                   18     4
   8                   19 24371
   9                   21   466
  10                   27     4
  </code></pre>
  
  <p>This is almost what I need. It is only necessary to order column n, from the largest quantity to the smallest quantity</p>
  
  <p>How to use dplyr to do this?</p>