Convert data from long format to wide format with multiple measure columns

前端 未结 5 2156
灰色年华
灰色年华 2020-11-22 02:27

I am having trouble figuring out the most elegant and flexible way to switch data from long format to wide format when I have more than one measure variable I want to bring

5条回答
  •  面向向阳花
    2020-11-22 03:20

       reshape(my.df,
               idvar = "ID",
               timevar = "TIME",
               direction = "wide")
    

    gives

      ID X.1 Y.1 X.2 Y.2 X.3 Y.3 X.4 Y.4 X.5 Y.5
    1  A   1  16   4  19   7  22  10  25  13  28
    2  B   2  17   5  20   8  23  11  26  14  29
    3  C   3  18   6  21   9  24  12  27  15  30
    

提交回复
热议问题