[Rd] ave reports warning when nothing is wrong

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 15 14:45:38 CET 2011


ave reports a warning here:

> DF <- data.frame(A = c(1, 2, 2), B = c(1, 1, 2), C = c(1, 2, 3))
> with(DF, ave(C, A, B, FUN = min))
[1] 1 2 3
Warning message:
In FUN(X[[4L]], ...) : no non-missing arguments to min; returning Inf

In this case it can be avoided by using drop = TRUE which could only
be discovered by looking at the source code and at any rate should not
be necessary:

> with(DF, ave(C, A, B, drop = TRUE, FUN = min))
[1] 1 2 3

The problem is that internally ave uses interaction(...) -- in the
example above that would correspond to interaction(A, B).  This can
result in a factor with unused levels.  Replacing   interaction(...)
in the source code with
   interaction(..., drop = TRUE)
would avoid the warning message.

> ave
function (x, ..., FUN = mean)
{
    n <- length(list(...))
    if (n) {
        g <- interaction(...)
        split(x, g) <- lapply(split(x, g), FUN)
    }
    else x[] <- FUN(x)
    x
}
<environment: namespace:stats>

> R.version.string
[1] "R version 2.12.1 Patched (2010-12-16 r53864)"

I got the same results with:
> R.version.string
[1] "R version 2.13.0 Under development (unstable) (2011-02-11 r54330)"
>


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-devel mailing list