[R] reshape (a better way)

Thomas Lumley tlumley at u.washington.edu
Wed Jan 26 21:08:46 CET 2005


On Wed, 26 Jan 2005, Jean Eid wrote:

>
> Hi,
>
> I am using the NLSY79 data (longitudinal data from the Bureau of labour
> stats in the US). The extractor exctracts this data in a "wide" format and
> I need to reshape it into a long format.
>
> What I am doing right now is to do it in chuncks for each and evry
> variable that is varying and then I merge the data together. This is
> taking a long time. my question is:
>
> How do I specify that there are multiple variables that are varying in
> reshape. Is there a way to do this?

Yes. The help page says

varying: names of sets of variables in the wide format that correspond
           to single variables in long format ('time-varying').  A list
           of vectors (or optionally a matrix for 'direction="wide"').
           See below for more details and options.

That is, you can use something like

varying=list(c("foo1","foo2","foo3"),
          c("bar1","bar2","bar3"),
          c("baz1","baz2","baz3")),
v.names=c("foo","bar","baz")


 	-thomas




More information about the R-help mailing list