[R] data manipulation

Jim Porzak jporzak at gmail.com
Thu Sep 8 19:37:52 CEST 2005


Also see Hadley Wickham's reshape package for more bells & whistles.
-- 
HTH!
Jim Porzak
Loyalty Matrix Inc.



On 9/8/05, Thomas Lumley <tlumley at u.washington.edu> wrote:
> 
> This is what reshape() does.
> 
>         -thomas
> 
> On Thu, 8 Sep 2005, Marc Bernard wrote:
> 
> > Dear All,
> >
> > I would be grateful if you can help me. My problem is the following:
> > I have a data set like:
> >
> > ID  time      X1          X2
> > 1    1          x111      x211
> > 1    2          x112      x212
> > 2    1          x121      x221
> > 2    2          x122      x222
> > 2    3          x123      x223
> >
> > where X1 and X2 are 2 covariates and "time" is the time of observation and ID indicates the cluster.
> >
> > I want to merge the above data by creating a new variable  "X" and "type" as follows:
> >
> > ID   time    X            type
> > 1     1      x111         X1
> > 1     2      x112         X1
> > 1     1      x211         X2
> > 1     2      x212         X2
> > 2     1      x121         X1
> > 2     2      x122         X1
> > 2     3      x123         X1
> > 2     1      x221         X2
> > 2     2      x222         X2
> > 2     3      x223         X2
> >
> >
> > Where "type" is a factor variable indicating if the observation is related to X1 or X2...
> >
> > Many thanks in advance,
> >
> > Bernard
> >
> >
> > ---------------------------------
> >
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> >
> 
> Thomas Lumley                   Assoc. Professor, Biostatistics
> tlumley at u.washington.edu        University of Washington, Seattle
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list