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 = "_"'?
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
Thanks,
Stephen
--
Rochester, Minn. USA
>>>>> "SW" == Stephen Weigand <weigand.stephen at gmail.com> >>>>> on Tue, 31 Mar 2009 18:33:05 -0500 writes:SW> I wonder if the 'sep' argument in reshape() is being ignored SW> unintentionally: No. It is used much differently than you *assume* it's used. As always, ?reshape contains the answer. SW> ## From example(reshape) SW> df <- data.frame(id=rep(1:4,rep(2,4)), SW> visit=I(rep(c("Before","After"),4)), SW> x=rnorm(4), y=runif(4)) SW> reshape(df, timevar="visit", idvar="id", direction="wide", sep = "_") SW> id x.Before y.Before x.After y.After SW> 1 1 0.773 0.293 -0.021 0.658 SW> 3 2 -0.518 0.351 -0.623 0.946 SW> 5 3 0.773 0.293 -0.021 0.658 SW> 7 4 -0.518 0.351 -0.623 0.946 SW> Is this more of the intended result when 'sep = "_"'? SW> id x_Before y_Before x_After y_After SW> 1 1 0.773 0.293 -0.021 0.658 SW> 3 2 -0.518 0.351 -0.623 0.946 SW> 5 3 0.773 0.293 -0.021 0.658 SW> 7 4 -0.518 0.351 -0.623 0.946 no it is not. I tend to agree that I would have preferred a different argument name than 'sep' for the current 'sep', and then a *further* argument 'sep' with the functionality that you'd like would be straightforward. Martin Maechler, ETH Zurich
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