Re: [R] Reshape Dataframe

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Wed, 19 Dec 2007 11:56:55 -0500 (EST)


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.
>



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 Wed 19 Dec 2007 - 16:59:53 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 - 18:30:20 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.