From jefferis at mrc-lmb.cam.ac.uk  Tue Nov 11 00:27:22 2014
From: jefferis at mrc-lmb.cam.ac.uk (Dr Gregory Jefferis)
Date: Mon, 10 Nov 2014 23:27:22 +0000
Subject: [Rd] subscripting a data.frame (without changing row order)
 changes internal row.names
In-Reply-To: <CAJXgQP3kwH=dGF8+2PBB_5A5aN8K54EpeJNs5qPC5WGoMsEg7w@mail.gmail.com>
References: <E2D19D2D-FFB7-4A28-A6F1-2F72DA776C4A@mrc-lmb.cam.ac.uk>
	<CAPPM_gRVgG78CNDfuqPZN0svHCgA5UHKvLcFUsOYsXhhYLKi3Q@mail.gmail.com>
	<CAJXgQP3kwH=dGF8+2PBB_5A5aN8K54EpeJNs5qPC5WGoMsEg7w@mail.gmail.com>
Message-ID: <CBBA192D-F1B2-441D-A4B1-758C87A4A362@mrc-lmb.cam.ac.uk>

Hi Kevin, Joshua,

Many thanks for this additional information.

On 10 Nov 2014, at 22:21, Kevin Ushey wrote:

> I believe the question here is related to the sign on the compact row
> names representation: why is it sometimes `c(NA, <positive>)` and
> sometimes `c(NA, <negative>)` -- why the difference in sign?

It was indeed the difference in sign that Kevin highlights that was 
puzzling me

> To the best of my knowledge, older versions of R used the signed-ness
> of compact row.names to differentiate between different 'types' of
> data.frames, but that should no longer be necessary. Unless there is
> some reason not to, I believe R should standardize on one
> representation, and consider it a bug if the other is seen.

[snip, Joshua wrote ]

>> Look at ?.row_names_info (which is mentioned in the See Also section
>> of ?row.names) and its type argument.

>> The first are "automatic".  The second are a compact form of 1:10, as
>> mentioned in ?row.names.  I'm not certain of the root cause/reason,
>> but the second object will not have "automatic" rownames because you
>> have subset it with a non-missing 'i'.

Quoting ?.row_names_info for

> .row_names_info(x, type = 1L)

> Currently type = 0 returns the internal "row.names" attribute 
> (possibly NULL), type = 2 the number of rows implied by the attribute, 
> and type = 1 the latter with a negative sign for ?automatic? row 
> names.

> .row_names_info(df2)
[1] 10
> .row_names_info(df)
[1] -10

So indeed the first case is marked as automatic, the second not.

Thanks again,

Greg.

--
Gregory Jefferis, PhD                   Tel: 01223 267048
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://jefferislab.org
http://flybrain.stanford.edu



[Rd] subscripting a data.frame (without changing row order) changes internal row.names
Dr Gregory Jefferis