Long to wide w/ two repeated measures

前端 未结 2 2097
無奈伤痛
無奈伤痛 2021-01-02 03:35

I know this has been asked numerous times on here under the rubric of \"long to wide\" but I\'ve run into a situation where I have two value variables that are repeated meas

2条回答
  •  清歌不尽
    2021-01-02 04:02

    I think this will do it:

    library(reshape)
    m <- melt(DF)
    

    Simplest, but time and score are in the opposite order from your example (in case it matters)

    cast(m,id+sex~...)
    

    Or more explicitly:

    cast(m,id+sex~variable+time)
    

    You can cut this down to a one-liner:

    recast(DF,id+sex~...)
    

    If you like you can use the newer reshape2 package instead of reshape, replacing cast with dcast (the version of recast included in reshape2 doesn't give the desired result.)

提交回复
热议问题