Skip to content
Prev 25044 / 63424 Next

Unexpected alteration of data frame column names

On Mon, 2007-05-14 at 23:59 -0700, Herve Pages wrote:
Herve,

I had not seen a reply to your post, but you can review the code for
"[.data.frame" by using:

  getAnywhere("[.data.frame")

and see where there are checks for duplicate column names in the
function.

That is going to be the default behavior for data frame
subsetting/extraction and in fact is noted in the 'ONEWS' file for R
version 1.8.0:

 - Subsetting a data frame can no longer produce duplicate
   column names.

So it has been around for some time (October of 2003).

In terms of avoiding it, I suspect that you would have to create your
own version of the function, perhaps with an additional argument that
enables/disables that duplicate column name checks.

I have not however considered the broader functional implications of
doing so however, so be vewwy vewwy careful here.

HTH,

Marc Schwartz