From maechler at stat.math.ethz.ch  Wed Apr  1 09:32:41 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 1 Apr 2009 09:32:41 +0200
Subject: [Rd] 'sep' argument in reshape()
In-Reply-To: <bc47d3330903311633m6e90c73dn32b48d7e984276d4@mail.gmail.com>
References: <bc47d3330903311633m6e90c73dn32b48d7e984276d4@mail.gmail.com>
Message-ID: <18899.6297.627838.913631@lynne.math.ethz.ch>

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



[Rd] 'sep' argument in reshape()
Martin Maechler