I have a dataset that looks like:
order year value
1 1990 2
1 1990 1
1 1990 1
2 1990 0
3 1990 4
1 1991 3
2 1991 2
2 1991 0
I have been trying to get the count of the unique orders in particular year. I tried table(data$year) which gives me:
1990 1991
5 3
However, I would like to get:
1990 1991
3 2
This will do the trick. It uses
tapply()to separately count the number of unique values oforderfor each level ofyear.