2017-10-05 101 views
0

DATA轉換數據幀一些列成行

我有這樣一個數據幀:

id weigth temp_s1 temp_s2 
    1  50  2  7 
    2  51  3  8 
    3  52  4  9 
    4  53  5  10 
    5  54  6  11 

我想要什麼

我想獲得這樣的:

 id weigth temp value 
     1  50 temp_s1  2 
     1  50 temp_s2  7 
     1  51 temp_s1  3 
     1  51 temp_s2  8 
     1  52 temp_s1  4 
     1  52 temp_s2  9 
     1  53 temp_s1  5 
     1  53 temp_s2  10 
     1  54 temp_s1  6 
     1  54 temp_s2  11 
+0

你能發佈dput的結果對你的DF? – Pop

+0

無法檢查沒有數據嘗試,但'dat%>%tidyr :: gather(temp,value,-weight)'? – Phil

回答

1

您應該使用melt功能從reshape2包如下:

melt(df, c("id", "weight"))