reshape data in r when reshape cannot guess the names of the time varying variables reshape data in r when reshape cannot guess the names of the time varying variables r r

reshape data in r when reshape cannot guess the names of the time varying variables


Add the v.names argument:

reshape(u,varying=2:10,direction="long", v.names=c("f", "u", "i"))    id time          f          u             i1.1  1    1  1.7821678  0.5144692  0.00068899282.1  2    1 -0.5036801  1.8242030  0.96955538173.1  3    1  1.1857706  0.6469423  0.67756021754.1  4    1 -0.5759202 -1.0349980  0.71834511465.1  5    1 -2.3559773  0.8598020  0.55063394756.1  6    1 -0.8047651 -1.4768172 -0.3667918383...


I see Andrie's solution, but perhaps my efforts at understanding rehape syntax can also be useful. The 'varying' argument is supposed to be a named vector (or list) with the column indices grouped by name:

reshape(u, varying=c( f=c(2,5,8), u=c(3,6,9), i=c(4,7,10) ), direction="long")

And this would also have worked (since the names imply a grouping):

 reshape(u,varying=names(u)[2:10], direction="long")

I went back and tried your code and found that it also worked, so I'm wondering if you wanted something different that we are guessing?


Just add option sep = "" to let reshape knows that your columns name is not separate by ..