[Rd] data frame with NA in names

Benjamin Tyner btyner at gmail.com
Fri Feb 15 21:01:09 CET 2008


When calling read.table() and supplying colClasses and header=FALSE,
it is possible for the resulting data frame to have NA in the names.
(The warning "not all columns named in 'colClasses' exist" is
returned)

Here is such a data frame:

x <- structure(list(a = 1:10,
                    "NA" = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)),
                    .Names = c("a", NA_character_),
                    row.names = c(NA, -10L),
                    class = "data.frame")

One undesirable property of such a data frame is that subset() has
trouble with it:

subset(x, a > 5)

Error in `[.data.frame`(x, r, vars, drop = drop) :
  undefined columns selected


Is this a bug in read.table() ?

Thanks
Ben



More information about the R-devel mailing list