I am trying to get a simple way to count the number of distinct categories in a column of a dataframe.
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.
I was thinking something like this:
df <- iris
choices <- count(unique(iris$Species))
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.
count number of instances in data frame
Count number of occurrences of categorical variables in data frame (R)
How to count number of unique character vectors within a subset of data