[Rd] Incorrect behaviour of [.data.frame (PR#13628)

waku at idi.ntnu.no waku at idi.ntnu.no
Sat Mar 28 09:40:15 CET 2009


Full_Name: Wacek Kusnierczyk
Version: 2.8.0 and 2.10.0 r48231
OS: Ubuntu 8.04 Linux 32 bit
Submission from: (NULL) (80.202.30.36)


According to the R Language definition (sec. 3.4.3), [.data.frame has the
following properties:

"if two indices are supplied (even if one is empty) it creates matrix-like
indexing for a structure that is basically a list of vectors of the same length.
If a single index is supplied, it is interpreted as indexing the list of
columns—in that case the drop argument is ignored, with a warning."

A similar explanation is given in ?'[.data.frame'.  However, in specific cases,
this is not how [.data.frame works:

   # dummy demo data frame
   d = data.frame(matrix(1:9, 3, 3))

   d[j=1]
   # the whole data frame

The example illustrates behaviour that is incorrect wrt. the documentation: 
only a single index is given, but it is not that the respective columns are
selected.

This might be an implementational bug (i.e., the function ignores the argument
because it is explicitly named 'j', and ignores the argument j because only one
index is given); in which case the implementation should be improved.

This might also be an intended feature that is not appropriately documented; in
which case the documentation should be improved.

It is hard for me to judge which is the case, because there is no clear
specification of what [.data.frame should do in specific situations.

Regards,
Wacek



More information about the R-devel mailing list