What's wrong with using t
ranspose on your data.frame
?
If you want to use "reshape2", you can try the following:
mydataLong <- melt(mydata, id.vars="Destination")
mydataLong
# Destination variable value
# 1 D1 S1 94
# 2 D2 S1 94
# 3 D3 S1 94
# 4 D4 S1 10
# 5 D1 S2 87
# 6 D2 S2 87
# 7 D3 S2 87
# 8 D4 S2 95
# 9 D1 S3 84
# 10 D2 S3 84
# 11 D3 S3 84
# 12 D4 S3 92
# 13 D1 S4 75
# 14 D2 S4 75
# 15 D3 S4 75
# 16 D4 S4 83
In base R, you can try the following for the long output:
cbind(mydata[1], stack(mydata[-1]), row.names = NULL)
If you wanted that compact transposed output, you would do this:
dcast(mydataLong, variable ~ Destination)
# variable D1 D2 D3 D4
# 1 S1 94 94 94 10
# 2 S2 87 87 87 95
# 3 S3 84 84 84 92
# 4 S4 75 75 75 83