[Rd] nrow(rbind(character(), character())) returns 2 (as documented but very unintuitive, IMHO)
Gabriel Becker
g@bembecker @end|ng |rom gm@||@com
Fri May 17 01:11:57 CEST 2019
On Thu, May 16, 2019 at 3:47 PM Gabriel Becker <gabembecker using gmail.com>
wrote:
> Hi Hadley,
>
> Thanks for the counterpoint. Response below.
>
> On Thu, May 16, 2019 at 1:59 PM Hadley Wickham <h.wickham using 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]]
More information about the R-devel
mailing list