Re: [R] More elegant way of stacking the data

2014-11-25 Thread Lee, Chel Hee
If you do not want to use the loop, a function called 'reshape' may be useful: > df <- data.frame(a=1:5,b=letters[1:5],c1=1:5,c2=2:6,c3=3:7,c4=4:8) > out2 <- reshape(data=df, direction="long", varying=list(3:6), times=paste("c",1:4,sep="")) > out2 a b time c1 id 1.c1 1 a c1 1 1 2.c1 2

Re: [R] More elegant way of stacking the data

2014-11-25 Thread Dimitri Liakhovitski
Thanks a lot, guys! On Tue, Nov 25, 2014 at 9:42 AM, Lee, Chel Hee wrote: > If you do not want to use the loop, a function called 'reshape' may be > useful: > >> df <- data.frame(a=1:5,b=letters[1:5],c1=1:5,c2=2:6,c3=3:7,c4=4:8) >> out2 <- reshape(data=df, direction="long", varying=list(3:6), >>

Re: [R] More elegant way of stacking the data

2014-11-24 Thread David Winsemius
On Nov 24, 2014, at 3:12 PM, Dimitri Liakhovitski wrote: > I have the data frame 'df' and my desired solution 'out'. > I am sure there is a more elegant R-way to do it - without a loop. > > df = data.frame(a=1:5,b=letters[1:5],c1=1:5,c2=2:6,c3=3:7,c4=4:8) > mylist=NULL > for(i in 1:4){ > myname

[R] More elegant way of stacking the data

2014-11-24 Thread Dimitri Liakhovitski
I have the data frame 'df' and my desired solution 'out'. I am sure there is a more elegant R-way to do it - without a loop. df = data.frame(a=1:5,b=letters[1:5],c1=1:5,c2=2:6,c3=3:7,c4=4:8) mylist=NULL for(i in 1:4){ myname<-paste("c",i,sep="") mylist[[i]]<-df[c("a","b",myname)] names(mylis