melt anova shaped dataset with multiple measure vars and categories in R

Viewed 100

I know the question has probably already been asked, but I couldn't find instances of the specific problem I'm facing with melting at the presence of multiple measure vars. I have a data table like this.

library(data.table)
set.seed(234)
DT<-data.table(item=1:3,phase=c("pre-test","test","follow up"),
               control_RT=sample(400:600,3),control_ecc=sample(100:200,3),
               oa_RT=sample(500:700,3),oa_ecc=sample(200:250,3),ya_RT=sample(450:550,3),ya_ecc=sample(230:260,3))

All I need to do is to put the variables RT and ecc in two separate columns by category, and add a column in which the category is specified:

 item   phase       RT  ecc  Category
    1   pre-test    549 178 control
    2   test        556 106 control
    3   follow up   403 163 control
    1   pre-test    686 214 oa
    2   test        643 227 oa
    3   follow up   684 226 oa
    1   pre-test    508 243 ya
    2   test        550 239 ya
    3   follow up   450 251 ya

I tried to use reshape with varying function but had no success. Any advice?

2 Answers
Related