Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • why is sd(numeric(1))==NA (and not NaN)?

    0 answers - 1215 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I am just curious about this, and could not find anything in the help
    pages or the list archives. ?var mentions that for a vector of length
    1 it gives NA instead of NaN as S-Plus does.
    mean(numeric(0))==NaN, this makes sense since it is 0/0.
    sd(numeric(1))==NA, but it is sqrt(0/0), so it makes more sense to me
    as NaN.
    Perhaps sd(numeric(0)) (and var) could return NA then
    Please understand that I am not proposing a change to R (which is a
    very well-polished language) but would like to know the reasons for
    the above.
    The issue came up when I was evaluating MCMC simulations. I needed to
    know the conditional mean and standard deviation of some variable
    given that it is nonzero, so I removed the zeroes and used mean() and
    sd() on it, not thinking about the case when all draws are zero. When
    that happened, mean() gave NaN gracefully, but sd() (of course, in
    compliance with ?var) failed. I don't see why NA would be so bad in
    that case, if somebody could please explain as there must be a reason.
    Thank you,
    Tamas
    R-help (AT) stat (DOT) math.ethz.ch mailing list
    PLEASE do read the posting guide!

Re: why is sd(numeric(1))==NA (and not NaN)?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "Development"

EMSDN.COM