s-news
[Top] [All Lists]

Re: stacking columns

To: Sundar Dorai-Raj <sundar.dorai-raj@PDF.COM>
Subject: Re: stacking columns
From: "Henrik Aalborg Nielsen" <immhan@student.dtu.dk>
Date: Wed, 22 Oct 2003 11:00:29 +0200 (MEST)
Cc: Mathangi Gopalakrishnan <mathangi@msn.com>, s-news@lists.biostat.wustl.edu
In-reply-to: <3F8E8208.3040405@pdf.com>
References: <BAY3-F10KXjlReXmRe000012151@hotmail.com> <3F8E8208.3040405@pdf.com>
Using only standard S-PLUS, I would use:

        do.call("c", x[,-1]) # A data frame is also a list

or maybe

        cbind(rep(x[,1], ncol(x)-1), do.call("c", x[,-1]))

Regards,
Henrik

On Thu, 16 Oct 2003, Sundar Dorai-Raj wrote:

> Would "reShape" in library(Hmisc) do what you need?
>
> x <- data.frame(id = 1:5)
> x$y4 <- x$y3 <- x$y2 <- x$y1 <- rnorm(5)
> reShape(x, base = "y", reps = 4)
>
> Hope this helps,
>
> -sundar
>
> Mathangi Gopalakrishnan wrote:
>
> > Hello
> > I have a dataframe with 7 rows and 5 columns.  I want to write a s-plus
> > command to stack columns 2 to 5.  In GUI i used the stack option to do
> > the same.
> > How do i write the command?
> > Could somebody help me on this?
> > Thank you
> >
> > Best Wishes,
> > Mathangi Gopalakrishnan
> >
> > _________________________________________________________________
> > Add MSN 8 Internet Software to your current Internet access and enjoy
> > patented spam control and more.  Get two months FREE!
> > http://join.msn.com/?page=dept/byoa
> >
> > --------------------------------------------------------------------
> > This message was distributed by s-news@lists.biostat.wustl.edu.  To
> > unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> > the BODY of the message:  unsubscribe s-news
>
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news
>

<Prev in Thread] Current Thread [Next in Thread>