wide to long multiple measures each time

后端 未结 5 1372
慢半拍i
慢半拍i 2020-12-01 06:45

I know the wide to long has been asked way too many times on here but I can\'t figure out how to turn the following into long format. Shoot I even asked one of the wide to

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 07:38

    This is pretty close and changing the names of columns should be within your skillset:

    reshape(DF, 
           varying=c(work= c(3, 7), play= c(4,8), talk= c(5,9), total= c(6,10) ), 
           direction="long")
    

    EDIT: Adding a version that is almost an exact solution:

    reshape(DF, varying=list(work= c(3, 7), play= c(4,8), talk= c(5,9), total= c(6,10) ), 
            v.names=c("Work", "Play", "Talk", "Total"), 
              # that was needed after changed 'varying' arg to a list to allow 'times' 
            direction="long",  
            times=1:2,        # substitutes number for T1 and T2
            timevar="times")  # to name the time col
    

提交回复
热议问题