Say I have a dataframe df
:
c1 c2
A 1
A 3
A 1
A 3
B 3
B 3
B 3
I want to use this dataframe to generate a table that shows each unique value from c1
and the mean of its corresponding values from c2
, resulting in this:
v1 v2
A 2
B 3
because the mean of A's values is 2 ((1+1+3+3)/4) and B's is 3 ((3+3+3)/3).
I'm guessing I need to use aggregate but I'm not sure how.