[Rd] 'droplevels' inappropriate change

Suharto Anggono Suharto Anggono suharto_anggono at yahoo.com
Sat Aug 27 05:17:32 CEST 2016


In R devel r71157, 'droplevels' documentation, in "Arguments" section, says this about argument 'exclude'.
passed to factor(); factor levels which should be excluded from the result even if present.  Note that this was implicitly NA in R <= 3.3.1 which did drop NA levels even when present in x, contrary to the documentation.  The current default is compatible with x[ , drop=FALSE].

The part
x[ , drop=FALSE]
should be
x[ , drop=TRUE]

Saying that 'exclude' is factor levels is not quite true for NA element. NA may be not an original level, but NA in 'exclude' affects the result.

For a factor 'x', factor(x, exclude = exclude) doesn't really work for excluding in general. See, for example, https://stat.ethz.ch/pipermail/r-help/2005-September/079336.html .
factor(factor(c("a","b","c")), exclude="c")

However, this excludes "2":
factor(factor(2:3), exclude=2)

Rather unexpectedly, this excludes NA:
factor(factor(c("a",NA), exclude=NULL), exclude="c")

For a factor 'x', factor(x, exclude = exclude) can only exclude integer-like or NA levels. An explanation is in https://stat.ethz.ch/pipermail/r-help/2011-April/276274.html .



More information about the R-devel mailing list