I have data in the following structure:
x <- read.table(header=T, text=" XYDS ae 1 10 ae 2 20 af 1 50 bc 1 40 bc 2 30 bc 3 60 bd 1 10 bd 2 20")
And I want to get the following result:
XY 1 2 3 ae 10 20 af 50 bc 40 30 60 bd 10 20
For each combination of columns X and Y I would like to transpose the data in column S in order in column D
I thought xtabs() would work, but I donβt think so, my best version is:
xtabs(formula=S~Y+D,data=x)
As a result:
D Y 1 2 3 c 40 30 60 d 10 20 0 e 10 20 0 f 50 0 0
source share