From tlumley at u.washington.edu  Wed Apr  1 10:00:13 2009
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Wed, 1 Apr 2009 01:00:13 -0700 (PDT)
Subject: [Rd] 'sep' argument in reshape()
In-Reply-To: <bc47d3330903311633m6e90c73dn32b48d7e984276d4@mail.gmail.com>
Message-ID: <Pine.LNX.4.43.0904010100130.1167@hymn11.u.washington.edu>

On Tue, 31 Mar 2009, Stephen Weigand wrote:

> I wonder if the 'sep' argument in reshape() is being ignored
> unintentionally:
>
> ## From example(reshape)
> df <- data.frame(id=rep(1:4,rep(2,4)),
>                  visit=I(rep(c("Before","After"),4)),
>                  x=rnorm(4), y=runif(4))
>
> reshape(df, timevar="visit", idvar="id", direction="wide", sep = "_")
>
>  id x.Before y.Before x.After y.After
> 1  1    0.773    0.293  -0.021   0.658
> 3  2   -0.518    0.351  -0.623   0.946
> 5  3    0.773    0.293  -0.021   0.658
> 7  4   -0.518    0.351  -0.623   0.946
>
> Is this more of the intended result when 'sep = "_"'?

No. sep= is designed for going the other way.  If you have wide-format data with variable names x.Before y.Before x.After y.After, using sep="." will let reshape() work out that the long-format variable names are x and y and the conditions to be put in the time variable are Before and After.

    -thomas


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



[Rd] 'sep' argument in reshape()
Thomas Lumley