I have Input data like the one below and I want to know if there is any way to reshape it into an Excel format with a header and sub-header.
Input:
Cons rep name value
10 N=1 A 12
10 N=2 A 13
10 N=1 B 10
10 N=2 B 11
12 N=1 A 23
12 N=2 A 24
12 N=1 B 23
12 N=2 B 21
OutPut:
A B
N=1 N=2 N=1 N=2
10 12 13 10 11
12 23 24 23 21
I could get the below results using the dcast() function, but I want to know if there is a way to separate N=1 and N=2 as sub-header of A and B.
A_N1 A_N2 B_N1 B_N2
10 12 13 10 11
12 23 24 23 21