From p.dalgaard at biostat.ku.dk  Fri Oct 30 16:07:46 2009
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Fri, 30 Oct 2009 16:07:46 +0100
Subject: [Rd] weighted.mean uses zero when na.rm=TRUE (PR#14032)
In-Reply-To: <20091029180016.B4EEE282EFFB@mail.pubhealth.ku.dk>
References: <20091029180016.B4EEE282EFFB@mail.pubhealth.ku.dk>
Message-ID: <4AEB0142.40200@biostat.ku.dk>

arnima at hafro.is wrote:
> The weighted.mean() function replaces NA values with 0.0 when the user 
> specifies na.rm=TRUE:
> 
>    x <- c(101, 102, NA)
>    mean(x, na.rm=TRUE)                         # 101.5, correct
>    weighted.mean(x, na.rm=TRUE)                # 67.66667, wrong
>    weighted.mean(x, w=c(1,1,1), na.rm=TRUE)    # 67.66667, wrong
>    weighted.mean(x, w=c(1,1,1)/3, na.rm=TRUE)  # 67.66667, wrong
> 
> The weights are normalized w<-w/sum(w) before removing the NA values, 
> effectively replacing x[is.na(x)]<-0. This bug was introduced between 
> versions 2.9.2 and 2.10.0.

Yes,

r48644 on May 27, specifically.

-- 
    O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



[Rd] weighted.mean uses zero when na.rm=TRUE (PR#14032)
Peter Dalgaard