Count number of unique levels of a variable
<p>I am trying to get a simple way to count the number of distinct categories in a column of a dataframe.</p>

<p>For example, in the iris data frame, there are 150 rows with one of the columns being species, of which there are 3 different species.  I want to be able to run this bit of code and determine that there are 3 different species in that column.  I do not care how many rows each of those unique entries correspond to, just how many distinct variables there are, which is mostly what I found in my research.</p>

<p>I was thinking something like this:</p>

<pre><code>df &lt;- iris
choices &lt;- count(unique(iris$Species))
</code></pre>

<p>Does a solution as simple as this exist?  I have looked at these posts, but they either examine the entire data frame rather than a single column in that data frame or provide a more complicated solution than what I am hoping for.</p>

<p><a href="https://stackoverflow.com/questions/31501626/count-number-of-instances-in-data-frame">count number of instances in data frame</a></p>

<p><a href="https://stackoverflow.com/questions/36700028/count-number-of-occurrences-of-categorical-variables-in-data-frame-r">Count number of occurrences of categorical variables in data frame (R)</a></p>

<p><a href="https://stackoverflow.com/questions/38461540/how-to-count-number-of-unique-character-vectors-within-a-subset-of-data">How to count number of unique character vectors within a subset of data</a></p>