[Rd] suggestion for subset.data.frame()

Benjamin Tyner btyner at gmail.com
Thu Jun 23 03:55:04 CEST 2011


Currently, subset.data.frame() does

    if (missing(subset))
            r <- TRUE
        else {

perhaps better might be:

    if (missing(subset))
            r <- rep(TRUE, nrow(x))
        else {

The rationale being, if 'x' has zero rows and 'subset' is missing, we 
don't want to end up with more rows than we started with:

     > subset(head(iris, 0), select = -Species)
       Sepal.Length Sepal.Width Petal.Length Petal.Width
    NA           NA          NA           NA          NA


More information about the R-devel mailing list