how to transpose a dataframe

View: New views
8 Messages — Rating Filter:   Alert me  

how to transpose a dataframe

by roachyang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to transpose a dataframe like
      level   2006   2007   2008
        A       ....
        B      .....
        C        ........
into
      level    year
        A      2006    
        A      2007    
        A      2008
        B      2006
        B      2007
           ......
There is a procedure in SAS can do this, is there any function in R can do this?  
       

Re: how to transpose a dataframe

by Rolf Turner-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 10/07/2009, at 1:31 PM, roachyang wrote:

>
> I want to transpose a dataframe like
>       level   2006   2007   2008
>         A       ....
>         B      .....
>         C        ........
> into
>       level    year
>         A      2006
>         A      2007
>         A      2008
>         B      2006
>         B      2007
>            ......
> There is a procedure in SAS can do this, is there any function in R  
> can do
> this?

(a) ***Anything*** can be done in R; if there isn't a function to do it,
you can write one.

(b) ``Transpose'' is ***NOT*** the right word.  You probably mean  
``transform''.

(c) See ?reshape.

        cheers,

                Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

______________________________________________
R-help@... 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.

Re: how to transpose a dataframe

by milton ruser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

?reshape do the job.

bests
milton

On Thu, Jul 9, 2009 at 9:31 PM, roachyang <roachyang@...> wrote:

>
> I want to transpose a dataframe like
>      level   2006   2007   2008
>        A       ....
>        B      .....
>        C        ........
> into
>      level    year
>        A      2006
>        A      2007
>        A      2008
>        B      2006
>        B      2007
>           ......
> There is a procedure in SAS can do this, is there any function in R can do
> this?
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@... mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@... 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.

Re: how to transpose a dataframe

by Henrique Dallazuanna :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

try this:

transform(stack(DF, select = -level), values = DF$level)

On Thu, Jul 9, 2009 at 10:30 PM, roachyang <roachyang@...> wrote:

>
> I want to transpose a dataframe like
>      level   2006   2007   2008
>        A       ....
>        B      .....
>        C        ........
> into
>      level    year
>        A      2006
>        A      2007
>        A      2008
>        B      2006
>            ......
> There is a procedure in SAS can do this, is there any function in R can do
> this?
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@... 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.
>


--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]


______________________________________________
R-help@... 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.

Re: how to transpose a dataframe

by Bill.Venables :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Look at the 'reshape' package, with functions melt() and cast()

(I'm not sure how the remark about the virtues of SAS is relevant, but if you really want SAS, I presume you know where to find it.)
________________________________________
From: r-help-bounces@... [r-help-bounces@...] On Behalf Of roachyang [roachyang@...]
Sent: 10 July 2009 11:31
To: r-help@...
Subject: [R]  how to transpose a dataframe

I want to transpose a dataframe like
      level   2006   2007   2008
        A       ....
        B      .....
        C        ........
into
      level    year
        A      2006
        A      2007
        A      2008
        B      2006
        B      2007
           ......
There is a procedure in SAS can do this, is there any function in R can do
this?

--
View this message in context: http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@... 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@... 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.

Re: how to transpose a dataframe

by roachyang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Seems like this is the one, though I'm not sure how to use it.


Bill.Venables wrote:

>
> Look at the 'reshape' package, with functions melt() and cast()
>
> (I'm not sure how the remark about the virtues of SAS is relevant, but if
> you really want SAS, I presume you know where to find it.)
> ________________________________________
> From: r-help-bounces@... [r-help-bounces@...] On
> Behalf Of roachyang [roachyang@...]
> Sent: 10 July 2009 11:31
> To: r-help@...
> Subject: [R]  how to transpose a dataframe
>
> I want to transpose a dataframe like
>       level   2006   2007   2008
>         A       ....
>         B      .....
>         C        ........
> into
>       level    year
>         A      2006
>         A      2007
>         A      2008
>         B      2006
>         B      2007
>            ......
> There is a procedure in SAS can do this, is there any function in R can do
> this?
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@... 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@... 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.
>
>

--
View this message in context: http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24421173.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@... 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.

Parent Message unknown Re: how to transpose a dataframe

by roachyang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Seems like this is the one. But I got this message
"reached getOption("max.print") -- omitted 12259 rows",
and there are some data missing. What happened?


Bill.Venables wrote:

>
> Look at the 'reshape' package, with functions melt() and cast()
>
> (I'm not sure how the remark about the virtues of SAS is relevant, but if
> you really want SAS, I presume you know where to find it.)
> ________________________________________
> From: r-help-bounces@... [r-help-bounces@...] On
> Behalf Of roachyang [roachyang@...]
> Sent: 10 July 2009 11:31
> To: r-help@...
> Subject: [R]  how to transpose a dataframe
>
> I want to transpose a dataframe like
>       level   2006   2007   2008
>         A       ....
>         B      .....
>         C        ........
> into
>       level    year
>         A      2006
>         A      2007
>         A      2008
>         B      2006
>         B      2007
>            ......
> There is a procedure in SAS can do this, is there any function in R can do
> this?
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@... 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@... 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.
>
>

--
View this message in context: http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24421173.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@... 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.

Parent Message unknown Re: how to transpose a dataframe

by milton ruser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi roachyang,

you need to be more precise on your email.
But believe that you tryed one of the funtions like reshape or transform and
the output has been printed on your R session. If your dataset are large, is
better you assign your output on a object - like myobj<-reshape(...) - and
then save your table using write.table()... our explore your dataset using
head() or tail().
Bests

milton

On Thu, Jul 9, 2009 at 11:21 PM, roachyang <roachyang@...> wrote:

>
> Seems like this is the one. But I got this message
> "reached getOption("max.print") -- omitted 12259 rows",
> and there are some data missing. What happened?
>
>
> Bill.Venables wrote:
> >
> > Look at the 'reshape' package, with functions melt() and cast()
> >
> > (I'm not sure how the remark about the virtues of SAS is relevant, but if
> > you really want SAS, I presume you know where to find it.)
> > ________________________________________
> > From: r-help-bounces@... [r-help-bounces@...] On
> > Behalf Of roachyang [roachyang@...]
> > Sent: 10 July 2009 11:31
> > To: r-help@...
> > Subject: [R]  how to transpose a dataframe
> >
> > I want to transpose a dataframe like
> >       level   2006   2007   2008
> >         A       ....
> >         B      .....
> >         C        ........
> > into
> >       level    year
> >         A      2006
> >         A      2007
> >         A      2008
> >         B      2006
> >         B      2007
> >            ......
> > There is a procedure in SAS can do this, is there any function in R can
> do
> > this?
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > R-help@... mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> >
> > ______________________________________________
> > R-help@... mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24421173.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@... mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@... 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.