Skip to content
Prev 8988 / 63424 Next

density(), with argument of length 1 (PR#2593)

u9801539@leonard.anu.edu.au writes:
It comes from this bit of code:
function (x)
{
    hi <- sd(x)
    if (!(lo <- min(hi, IQR(x)/1.34)))
        (lo <- hi) || (lo <- abs(x[1])) || (lo <- 1)
    0.9 * lo * length(x)^(-0.2)
}

in which hi is NA if x has length 1. A pragmatic way out would seem to
be to change the first line to 

hi <- if (length(x) > 1) sd(x) else 0

(and I wonder why the author didn't go all the way with the ||
sneakiness and said

    (lo <- min(hi, IQR(x)/1.34)) ||
        (lo <- hi) || (lo <- abs(x[1])) || (lo <- 1)

)