[Rd] data.frame row.names=NULL with named vector

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Sun, 14 Oct 2007 11:40:25 -0700


A minor issue with data.frame is a change introduced leading to R 2.5.0, where row.names=NULL (i.e., do not name rows) is not honored with a named vector

> x <- letters[1:3]
> names(x) <- x
> data.frame(x, row.names=NULL)

  x
a a
b b
c c

and a slightly more subtle example

> data.frame(y=1:3, x, row.names=NULL)

  y x
a 1 a
b 2 b
c 3 c

A 2.5.0 news entry says

    o	data.frame() ignored 'row.names' for 0-column data frames, and
	no longer treats an explicit row.names=NULL differently from
	the default value.

The relevant section of ?data.frame however says

     If 'row.names' was supplied as 'NULL' or no suitable component
     was found the row names are the integer sequence starting at one

This is not consistent with the current behavior, and is unchanged from the pre 2.5.0 version. The workaround is distinctly hackish

> df <- data.frame(x)
> row.names(df) <- NULL

> sessionInfo()

R version 2.7.0 Under development (unstable) (2007-10-13 r43163) x86_64-unknown-linux-gnu

Martin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 14 Oct 2007 - 18:43:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Oct 2007 - 11:37:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.