I have a data frame in R whereby a value, attributed to a group, is repeated multiple times per group.
Sample data frame below:
Name Group
John A
John A
John A
John B
John B
John C
Sally A
Sally A
Sally B
Mark A
Mark B
Mark B
Mark C
I'm trying to count the number of times each Name occurs, as well as an output showing within how many groups they occur. So, the desired output would be below:
Name Observations No. of Groups
1 John 6 3
2 Sally 3 2
3 Mark 4 3
In the case of John, we can see that there are a total of 6 observations across three groups, whereas there are 3 observations of Sally across two groups.
Is there a single function or formula that can perform this to yield the desired output? Thanks in advance.