[Rd] subscripting a data.frame (without changing row order) changes internal row.names
Dr Gregory Jefferis
jefferis at mrc-lmb.cam.ac.uk
Tue Nov 11 00:27:22 CET 2014
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
> 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
So indeed the first case is marked as automatic, the second not.
Gregory Jefferis, PhD Tel: 01223 267048
Division of Neurobiology
MRC Laboratory of Molecular Biology
Francis Crick Avenue
Cambridge Biomedical Campus
Cambridge, CB2 OQH, UK
More information about the R-devel