I am trying to re-organize my data frame using reshape2
library. Even though convincing, I am not able to get the expected result.
Here is my data.frame
on hand.
> mydata
Destination S1 S2 S3 S4
1 D1 94 87 84 75
2 D2 94 87 84 75
3 D3 94 87 84 75
4 D4 10 95 92 83
Here is what I am expecting.
Source Destination Value
S1 D1 94
S2 D1 87
S3 D1 84
S4 D1 75
S1 D2 94
S2 D2 87
S3 D2 84
S4 D2 75
S1 D3 94
S2 D3 87
S3 D3 84
S4 D3 75
S1 D4 10
S2 D4 95
S3 D4 92
S4 D4 83
I tried to transpose the data.frame
, using the below:
> mydata.T <- t(mydata[,2:ncol(mydata)])
>
> mydata.T
S1 94 94 94 10
S2 87 87 87 95
S3 84 84 84 92
S4 75 75 75 83
I tried with melt
, but I am not able to get the exact result.
Can someone please help me here?