Categorize continuous variable with dplyr
<p>I want to create a new variable with 3 arbitrary categories based on continuous data.</p>

<pre><code>set.seed(123)
df &lt;- data.frame(a = rnorm(100))
</code></pre>

<p>Using base I would</p>

<pre><code>df$category[df$a &lt; 0.5] &lt;- "low"
df$category[df$a &gt; 0.5 &amp; df$a &lt; 0.6] &lt;- "middle"
df$category[df$a &gt; 0.6] &lt;- "high"
</code></pre>

<p>Is there a dplyr, I guess <code>mutate()</code>, solution for this?</p>

<p>Furthermore, is there a way to calculate the categories rather than choosing them? I.e. let R calculate where the breaks for the categories should be.</p>

<p>EDIT</p>

<p>The answer is in this <a href="https://stackoverflow.com/questions/23163567/r-dplyr-categorize-numeric-variable-with-mutate">thread</a>, however, it does not involve labelling, which confused me (and may confuse others) therefore I think this question serves a purpose.</p>