Re: [R] density with weights missing values

2021-07-13 Thread Göran Broström
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 R say that the weights must add up to 1? ?density doesn't say that in

Re: [R] density with weights missing values

2021-07-13 Thread Matthias Gondan
. 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 >>>>>

Re: [R] density with weights missing values

2021-07-13 Thread Martin Maechler
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: Matthias Gondan > Betreff: Re: [R] density

Re: [R] density with weights missing values

2021-07-12 Thread Duncan Murdoch
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,

Re: [R] density with weights missing values

2021-07-12 Thread Jeff Newmiller
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 mis

Re: [R] density with weights missing values

2021-07-12 Thread matthias-gondan
: 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 missing data

Re: [R] density with weights missing values

2021-07-12 Thread Jeff Newmiller
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 observati

Re: [R] density with weights missing values

2021-07-12 Thread Bert Gunter
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 > > > > > > > > > > Von: Richard O'

Re: [R] density with weights missing values

2021-07-12 Thread matthias-gondan
?  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 values

Re: [R] density with weights missing values

2021-07-12 Thread Bert Gunter
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 >

Re: [R] density with weights missing values

2021-07-12 Thread Matthias Gondan
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 at 22:42,

[R] density with weights missing values

2021-07-12 Thread Matthias Gondan
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