Re: [R] Reconfiguring wide frame to long frame

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 19 Jul 2006 - 03:36:22 EST

Sorry, in looking at this again my previous code did not give the same ordering you indicated. Instead using the same DF try this:

rbind(as.matrix(DF[,1:2]), as.matrix(DF[,3:4]))

Both this and the last piece of code produce matrices so use as.data.frame if you want a data frame.

On 7/18/06, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> Try this:
>
> # set up test data
> Lines <- "ID meas ID.1 meas.1
> 1 1.1 3 1.2
> 2 2.1 4 2.2
> "
> DF <- read.table(textConnection(Lines), header = TRUE)
>
> # reshape
> matrix(t(DF), nc = 2, byrow = TRUE, dimnames = list(NULL, colnames(DF)[1:2]))
>
>
> On 7/18/06, Jesse Albert Canchola <jesse.canchola.b@bayer.com> wrote:
> > Greetings, fellow R'ers.
> >
> > How can I get this frame in R:
> >
> > ID meas ID.1 meas.1
> > 1 1.1 3 1.2
> > 2 2.1 4 2.2
> >
> > to look like this (stacking):
> >
> > ID meas
> > 1 1.1
> > 2 2.1
> > 3 1.2
> > 4 2.2
> >
> > It's not really the reshape function (or is it?) because we can consider
> > the additional columns, viz., ID.1 and meas.1, as independent of ID and
> > meas so it is basically a stacking problem (no longitudinal component). I
> > can't seem to find a good example to do this in the docs. Thanks for your
> > help.
> >
> > Regards,
> > Jesse
> >
> >
> >
> >
> >
> >
> >
> >
> > Jesse A. Canchola
> > Biostatistician III
> > Bayer Healthcare
> > 725 Potter St.
> > Berkeley, CA 94710
> > P: 510.705.5855
> > F: 510.705.5718
> > E: Jesse.Canchola.b@Bayer.Com
> >
> >
> >
> >
> >
> > _______________________________________________________________________________________________
> >
> > The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly use, print, copy, forward, or disclose any part of this message. Please also delete this e-mail and all copies and notify the sender. Thank you.
> >
> > For alternate languages please go to
http://bayerdisclaimer.bayerweb.com
> > _______________________________________________________________________________________________
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@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
> > and provide commented, minimal, self-contained, reproducible code.
> >
>



R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Wed Jul 19 03:46:38 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 19 Jul 2006 - 06:21:27 EST.

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