From g@bembecker @end|ng |rom gm@||@com  Fri May 17 01:11:57 2019
From: g@bembecker @end|ng |rom gm@||@com (Gabriel Becker)
Date: Thu, 16 May 2019 16:11:57 -0700
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: <CAD4oTHEdgMWjtDj31EsHc_7ZK4B3Jp1od0dx+AgfO1pWLkgi1Q@mail.gmail.com>

On Thu, May 16, 2019 at 3:47 PM Gabriel Becker <gabembecker at gmail.com>
wrote:

> 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.
>
> Also, I know that you said *each with size m*, but the generalization
> would be
>
> for n vectors with m = max(length(x_i))
> nrow(rbind(x_1, ..., x_n)) = m
>

Ugh, obviously that should say ==n, not =m and then we have
ncol(rbind(x_1, ..., x_n)) == m

~G



>
> And that is the behavior now as documented, but *only* when length(x_i)
> >0 for all i (or, currently, when m == 0, so all vectors are length 0).
>
> > nrow(rbind(1:5, numeric()))
>
> [1] 1
>
>
> So that is where I was coming from. Length-zero vectors don't add rows
> because they contain no observed information.
>
> I do see where you'er coming from, but it does make interrogating
> nrow(rbind(x_1, ..., x_n)) NOT mean  (give me the number of observations
> for which I have data), which is what it means in non-degenerate contexts,
> and that seems pretty important too.
>
> Robin does also have an interesting point below about argument names, but
> I'll leave that for another mail.
>
> Best,
> ~G
>

	[[alternative HTML version deleted]]



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