One thing about varying is that reshape ignores the names on the
varying list and makes you
specify them all over again even though it could know what they are.
Note that we  had to
specify that names(varying) is the v.names.

  DF <- structure(list(A1 = 10L, A2 = 5L, B1 = 11L, B2 = 5L, C1 = 21L,
      C2 = 10L), class = "data.frame", row.names = c(NA, -1L))

  let <- gsub("\\d", "", names(DF))
  num <- gsub("\\D", "", names(DF))

  varying <- split(names(DF), num)
  reshape(DF, dir = "long", varying = varying, v.names = names(varying),
    times = unique(let), timevar = "let")[-4]

On Sun, Apr 11, 2021 at 6:01 AM Deepayan Sarkar
<deepayan.sar...@gmail.com> wrote:
>
> On Wed, Mar 17, 2021 at 7:55 PM Michael Dewey <li...@dewey.myzen.co.uk> wrote:
> >
> > Comments in line
> >
> > On 13/03/2021 09:50, SOEIRO Thomas wrote:
> > > Dear list,
> > >
> > > I have some questions/suggestions about reshape.
> > >
> > > 1) I think a good amount of the popularity of base::reshape alternative 
> > > is due to the complexity of reshape documentation. It is quite hard (at 
> > > least it is for me) to figure out what argument is needed for 
> > > respectively "long to wide" and "wide to long", because reshapeWide and 
> > > reshapeLong are documented together.
> > > - Do you agree with this?
> > > - Would you consider a proposal to modify the documentation?
> > > - If yes, what approach do you suggest? e.g. split in two pages?
> >
> > The current documentation is much clearer than it was when I first
> > started using R but we should always strive for more.
> >
> > I would suggest leaving the documentation in one place but it might be
> > helpful to add which direction is relevant for each parameter by placing
> > (to wide) or (to long) as appropriate. I think having completely
> > separate lists is not needed
>
> I have just checked in some updates to the documentation (in R-devel)
> which hopefully makes usage clearer. Any further suggestions are
> welcome. We are planning to add a short vignette as well, hopefully in
> time for R 4.1.0.
>
> > > 2) I do not think the documentation indicates that we can use varying 
> > > argument to rename variables in reshapeWide.
> > > - Is this worth documenting?
> > > - Is the construct list(c()) really needed?
> >
> > Yes, because you may have more than one set of variables which need to
> > correspond to a single variable in long format. So in your example if
> > you also had 11 variables for the temperature as well as the
> > concentration each would need specifying as a separate vector in the list.
>
> That's a valid point, but on the other hand, direction="long" already
> supports specifying 'varying' as a vector, and it does simplify the
> single variable case. So we decided to be consistent and allow it for
> direction="wide" too, hopefully with loud enough warnings in the
> documentation about using the feature carelessly.
>
> Best,
> -Deepayan
>
> > Michael
> >
> > >
> > > reshape(Indometh,
> > >          v.names = "conc",
> > >          idvar = "Subject",
> > >          timevar = "time",
> > >          direction = "wide",
> > >          varying = list(c("conc_0.25hr",
> > >                           "conc_0.5hr",
> > >                           "conc.0.75hr",
> > >                           "conc_1hr",
> > >                           "conc_1.25hr",
> > >                           "conc_2hr",
> > >                           "conc_3hr",
> > >                           "conc_4hr",
> > >                           "conc_5hr",
> > >                           "conc_6hr",
> > >                           "conc_8hr")))
> > >
> > > Thanks,
> > >
> > > Thomas
> > > ______________________________________________
> > > R-devel@r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-devel
> > >
> >
> > --
> > Michael
> > http://www.dewey.myzen.co.uk/home.html
> >
> > ______________________________________________
> > R-devel@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to