I need to calculate all possible coefficients inside each group in a dataset, if I have this dataframe:
ID Country_code V1 V2
1 US 0.4 1
1 GB 0.6 2
1 AU 0.4 3
2 US 0.5 2
2 CL 0.4 2
I need this as an output:
ID Country_code coefV1 coefV2
1 US-GB 0.66 0.5
1 US-AU 1 0.33
1 GB-AU 1.5 0.66
2 US-CL 1.25 1
I thought of expanding the dataframe first, something like:
ID Country_code V1-1 V1-2 V2-1 V2-2
1 US-GB 0.4 0.6 1 2
1 US-AU 0.4 0.4 1 3
1 GB-AU 0.6 0.4 2 3
2 US-CL 0.5 0.4 2 2
But I couldn't do that either.
Any thoughts? Thanks!