I have a data frame similar to this:
data <- data.frame(
Location = rep(letters[1:10], each = 20),
ID = rep(1:40, each = 5)
)
I want to return a table that contains each unique Location
in one column and a count of the number of unique ID
s in each Location
in another column, so it will look like this:
Location Count
a 4
b 4
... ...
Note: in my actual data set there are different numbers of ID
s in each Location
, and there are other variables in other columns.
What is the best way to do this?