I have data like this:
ID <- c(1001,1001, 1001, 1002,1002,1002)
activity <- c(123,123,123, 456,456,789)
df<- data.frame(ID,activity)
I want to count the number of unique activity values within ID to end up with a dataframe like this:
N<- c(1,1,1,2,2,2)
data.frame(df,N)
So we can see that person 1001 did only 1 activity while person 1002 did two.
I think it can be done with aggregate but am happy to use another approach.