On Wed, 22 Sep 2004 12:16:10 +0000 (UTC), Gabor Grothendieck
<[EMAIL PROTECTED]> wrote :
>Suggest you use an S3 generic and a separate methods for factor, and
>in the future, other classes.
That's not a bad idea, but is it really worth the trouble? Why not
piggyback on the unique() generic, and define it as something like
is.constant <- function(x, na.rm = FALSE, ...) {
vals <- unique(x, ...)
if (na.rm) vals <- vals[!is.na(vals)]
# What should the value be for c(1, NA)? If FALSE is wanted,
length(vals) == 1
# but if NA is desired
# ifelse (any(is.na(vals)), NA, length(vals) == 1)
}
>Also to make it more consistent with
>other R functions have an na.rm= argument which defaults to TRUE.
The more common default is FALSE.
Duncan Murdoch
______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html