2.5
weighted.mean(c(1, 2, 3, NA), weights=c(1, 1, 1, 1))
[1] NA
weighted.mean(c(1, 2, 3, NA), weights=c(1, 1, 1, 1), na.rm=TRUE)
[1] 2
Von: Richard O'Keefe
Gesendet: Montag, 12. Juli 2021 13:18
An: Matthias Gondan
Betreff: Re: [R] density with weights missing values
Does your copy of
.
Best wishes,
Matthias
PS. Sorry for the HTML email. I’ve given up trying to fix such behavior.
Von: Martin Maechler
Gesendet: Dienstag, 13. Juli 2021 09:09
An: Matthias Gondan
Cc: r-help@r-project.org
Betreff: Re: [R] density with weights missing values
>>>>> Matthias Gonda
d then in
your report mention both density() and weighted.mean(), i.e., a
cleaned up version of the union of your first 2 e-mails..
Thank you for thinking about this and concisely reporting it.
Martin
> Von: Richard O'Keefe
> Gesendet: Montag, 12. Juli 2021 13:18
> An: Ma
On 12/07/2021 1:22 p.m., matthias-gondan wrote:
You're right, of course. Extrapolating your argument a bit, the whole practice
of na.rm is questionable, since there's always a reason for missingness (that
is not in x and rarely elsewhere in the data)Best wishes Matthias
For what it's worth, I
12.07.21 18:44 (GMT+01:00) An:
>r-help@r-project.org, matthias-gondan , Bert
>Gunter Cc: r-help@r-project.org Betreff: Re:
>[R] density with weights missing values Sure, you might think that.But
>most likely the reason this code has not been corrected is that when
>you give weights
er
Datum: 12.07.21 18:44 (GMT+01:00) An:
r-help@r-project.org, matthias-gondan , Bert Gunter
Cc: r-help@r-project.org Betreff: Re: [R] density with
weights missing values Sure, you might think that.But most likely the reason
this code has not been corrected is that when you give weights for mi
dan Cc: r-help@r-project.org
>Betreff: Re: [R] density with weights missing values The behavior is as
>documented AFAICS.na.rmlogical; if TRUE, missing values are removed
>from x. If FALSE anymissing values cause an error.The default is
>FALSE.weightsnumeric vector of non-negative obse
eighted.mean(c(1, 2, 3, 4), weights=c(1, 1, 1, 1))
> > [1] 2.5
> > > weighted.mean(c(1, 2, 3, NA), weights=c(1, 1, 1, 1))
> > [1] NA
> > > weighted.mean(c(1, 2, 3, NA), weights=c(1, 1, 1, 1), na.rm=TRUE)
> > [1] 2
> >
> >
> >
> >
> >
thing?
Ursprüngliche Nachricht Von: Bert Gunter
Datum: 12.07.21 16:25 (GMT+01:00) An: Matthias
Gondan Cc: r-help@r-project.org Betreff: Re: [R]
density with weights missing values The behavior is as documented
AFAICS.na.rmlogical; if TRUE, missing values are removed from x. If FALSE
anymissing v
ghts=c(1, 1, 1, 1))
> [1] 2.5
> > weighted.mean(c(1, 2, 3, NA), weights=c(1, 1, 1, 1))
> [1] NA
> > weighted.mean(c(1, 2, 3, NA), weights=c(1, 1, 1, 1), na.rm=TRUE)
> [1] 2
>
>
>
>
> Von: Richard O'Keefe
> Gesendet: Montag, 12. Juli 2021 13:18
> An:
a.rm=TRUE)
[1] 2
Von: Richard O'Keefe
Gesendet: Montag, 12. Juli 2021 13:18
An: Matthias Gondan
Betreff: Re: [R] density with weights missing values
Does your copy of R say that the weights must add up to 1?
?density doesn't say that in mine. But it does check.
On Mon, 12 Jul 2021
Dear R users,
This works as expected:
• plot(density(c(1,2, 3, 4, 5, NA), na.rm=TRUE))
This raises an error
• plot(density(c(1,2, 3, 4, 5, NA), na.rm=TRUE, weights=c(1, 1, 1, 1, 1, 1)))
• plot(density(c(1,2, 3, 4, 5, NA), na.rm=TRUE, weights=c(1, 1, 1, 1, 1, NA)))
This seems to work (it trigge
12 matches
Mail list logo