[R] Reshape Dataframe

John Kane jrkrideau at yahoo.ca
Thu Dec 20 16:11:11 CET 2007


reshape package.


--- Bert Jacobs <b.jacobs at pandora.be> wrote:

> 
> 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)
> 
> --- Bert Jacobs <b.jacobs at pandora.be> wrote:
> 
> > 
> > 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/
> 
> 
>



More information about the R-help mailing list