[Rd] 'sep' argument in reshape()
Thomas Lumley
tlumley at u.washington.edu
Wed Apr 1 10:00:13 CEST 2009
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
More information about the R-devel
mailing list