Re: [R] Reshape Dataframe

From: Bert Jacobs <b.jacobs_at_pandora.be>
Date: Thu, 20 Dec 2007 15:27:21 +0100

In which package do I find the "cast" function. At the moment it's not recognized.
Thx,
Bert

-----Original Message-----
From: John Kane [mailto:jrkrideau_at_yahoo.ca] Sent: 19 December 2007 17:57
To: Bert Jacobs; 'hadley wickham'
Cc: r-help_at_stat.math.ethz.ch
Subject: Re: [R] Reshape Dataframe

I think if you use Gabor's suggested addtion of add.missing to the original cast command you get what you want.

cast(dfm, ... ~ Var3, add.missing=TRUE)

>
> Thx Hadley,
> It works, but I need some finetuning.
>
> If I use the following expression:
> Newdf <-reshape(df, timevar="Var3",
> idvar=c("Var1","Var2"),direction="wide")
>
> Newdf
> Var1 Var2 Var3.W1 Var3.W2 Var3.W3 var3.W4
> A Fa 1 3
> A Si 2 4
> B Si 5
> C La 6
> C Do 7
>
> Is there an option so that for each Var1 all
> possible combinations of Var2
> are listed (i.e. creation of blanco lines).
> Is it possible to name the columns with the values
> of the original Var3
> variable, so that the name Var3.W1 changes to W1?
>
> Var1 Var2 W1 W2 W3 W4
> A Fa 1 3
> A Si 2 4
> A La
> A Do
> B Fa
> B Si 5
> B La
> B Do
> C Fa
> C Si
> C La 6
> C Do 7
>
>
> Thx,
> Bert
>
> -----Original Message-----
> From: hadley wickham [mailto:h.wickham_at_gmail.com]
> Sent: 18 December 2007 15:16
> To: Bert Jacobs
> Cc: r-help_at_stat.math.ethz.ch
> Subject: Re: [R] Reshape Dataframe
>
> On 12/18/07, Bert Jacobs <b.jacobs_at_pandora.be>
> wrote:
> >
> > Hi,
> >
> > I'm having a bit of problems in creating a new
> dataframe.
> > Below you'll find a description of the current
> dataframe and of the
> > dataframe that needs to be created.
> > Can someone help me out on this one?
>
> library(reshape)
> dfm <- melt(df, id = 1:3)
> cast(dfm, ... ~ Var3)
>
> You can find out more about the reshape package at
> http://had.co.nz/reshape
>
> Hadley
>
> --
> http://had.co.nz/
>
> ______________________________________________
> R-help_at_r-project.org 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.
>

      Looking for a X-Mas gift? Everybody needs a Flickr Pro Account.  

http://www.flickr.com/gift/



R-help_at_r-project.org 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 Thu 20 Dec 2007 - 14:29:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 20 Dec 2007 - 15:30:21 GMT.

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