[R] transposing a data frame from horizontal to vertical (stacking)

From: Dimitri Liakhovitski <dimitri.liakhovitski_at_gmail.com>
Date: Tue, 29 Jun 2010 13:22:08 -0400

Hello, everyone!
I have a very simple task - I have a data frame (see MyData below) and I need to stack the data (see result below). I wrote the syntax below - it's very basic and it does what I need. But I am sure what I am trying to do is a very typical task and there must be a much shorter/more elegant way of doing it. Any advice?

Thank you very much!



### Creating a temp matrix with people as columns and months as rows: transposed<-apply(MyData[-1],1,t)

### Putting vertical data (months as rows) - for each person - into a list: list.of.stacked<-list()
for(i in 1:ncol(transposed)){


### Creating a data frame from the list: result<-do.call(rbind,list.of.stacked)

Dimitri Liakhovitski
Ninah Consulting

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 29 Jun 2010 - 17:24:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 Jun 2010 - 18:00:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive