From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Fri May 17 09:32:56 2019
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Fri, 17 May 2019 09:32:56 +0200
Subject: [Rd] nrow(rbind(character(),
 character())) returns 2 (as documented but very unintuitive, IMHO)
In-Reply-To: <CAD4oTHHFri915TAVkKw+EVz7c7niE9-wFijuB=_6hiqnkiHJRQ@mail.gmail.com>
References: <CAD4oTHFE9SUD2nrfLqoppBQv9QgQV2sA_qo9XA9JwuD+oRdz3g@mail.gmail.com>
 <CABdHhvF5bkFigyMO=nuC===1P0USbdoV+CSw7zfcVmw02YO9xw@mail.gmail.com>
 <CAD4oTHHFri915TAVkKw+EVz7c7niE9-wFijuB=_6hiqnkiHJRQ@mail.gmail.com>
Message-ID: <23774.25512.842877.618811@stat.math.ethz.ch>

>>>>> Gabriel Becker 
>>>>>     on Thu, 16 May 2019 15:47:57 -0700 writes:

    > Hi Hadley,
    > Thanks for the counterpoint. Response below.

    > On Thu, May 16, 2019 at 1:59 PM Hadley Wickham <h.wickham at gmail.com> wrote:

    >> The existing behaviour seems inutitive to me. I would consider these
    >> invariants for n vector x_i's each with size m:
    >> 
    >> * nrow(rbind(x_1, x_2, ..., x_n)) equals n
    >> 

    > Personally, no I wouldn't. I would consider m==0 a degenerate case, where
    > there is no data, but I personally find matrices (or data.frames) with rows
    > but no columns a very strange concept. The converse is not true, I
    > understand the utility of columns but no rows, particularly in the
    > data.frame case, but rows with no columns are observations we didn't
    > observe anything about. Strange, imho.

Gabe, here I have to very strongly disagree.

Matrices (and higher order Arrays)  are  always definitely to
behave "symmetrically" / "uniformly" with respect to all of their dimensions.

We (and the S developers before us) have always taken a lot of
care trying to ensure that this is true.

So for the matrix case, if rows and columns behaved differently
that would be a bug "by definition".

Of course there's one thing where this uniformity / symmetry
must be violated: in the coercion from and to atomic vectors:
There, 'by column' (generalized for arrays to "earlier dimensions vary faster
than later one") has been chosen, not the least because this had
been adapted for Fortran (first, AFAIK) and all related ABIs
dealing with Matrix vector arithmetic for very good (numerical,
performance, known convention) reasons that enabled to know how
fast numerical linear algebra should be implemented.

Martin



[Rd] nrow(rbind(character(), character())) returns 2 (as documented but very unintuitive, IMHO)
Martin Maechler