title: Column "rate" must be length 1 (a summary value), not 22906
body: <p>I am having some troubles with the below code. It returns</p>
  <blockquote>
  <p>&quot;Error in summarise_impl(.data, dots) : Column rate must be length 1 (a summary value), not 22906&quot;</p>
  </blockquote>
  <p>Is there any problem with my code?</p>
  <p><code>sub_grade</code> is of type character and <code>int_rate</code> is numeric</p>
  <pre><code>results &lt;- loan_data %&gt;%
    select(credit_grade, sub_grade, int_rate, loan_amnt) %&gt;%
    group_by(sub_grade) %&gt;%
    summarise(
      rate = substr(int_rate * 100, 1, 4),
      nr_loans = n(),
      &quot;&amp;&quot;,
      percent1 = substr((nr_loans / a) * 100, 1, 5),
      klj = &quot;&amp;&quot;,
      Amount = sum(loan_amnt, na.rm = TRUE),
      klj1 = &quot;&amp;&quot;,
      percent2 = substr((Amount / total) * 100, 1, 5)
    )
  </code></pre>
  <p>The problem shows up only when I add the first variable <code>rate</code>.</p>
  <p>Reproducible example:</p>
  <pre><code>sub_grade &lt;- c(&quot;A1&quot;, &quot;A2&quot;, &quot;A3&quot;,&quot;A1&quot;,&quot;A3&quot;)
  int_rate &lt;– c(0.023, 0.027, 0.033,0.023,0.033)
  </code></pre>
  <p>what I want is</p>
  <pre><code>sub_grade.  int_rate
  </code></pre>
  <ol>
  <li>A1.           0.023</li>
  <li>A2.           0.027</li>
  <li>A3.           0.033</li>
  </ol>