From: Duncan Murdoch <murdoch_at_stats.uwo.ca>

Date: Fri 11 Aug 2006 - 21:49:11 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 11 23:00:24 2006

Date: Fri 11 Aug 2006 - 21:49:11 EST

Yan Wong wrote:

> Hi, just a quick question:

*>
**> Should weighted.mean be able to cope with the specific case where one
**> weight is Inf? I came across this when trying to implement a simple
**> weighted moving average algorithm for surface smoothing: these
**> algorithms often result in a single infinite weight when predicting
**> the surface value at known data points.
**>
**> e.g.
**>
**> > weighted.mean(c(77,88,99), c(Inf, 1, 2)) #should this return 77?
**> [1] NaN
**>
**>
*

It makes sense in this case, but in the case where there is more than
one infinite weight, the result has to be NaN.

Right now the bit of weighted.mean that does the calculations is

sum(x * w)/sum(w)

and this would be a lot more complicated if it were to handle this very special case.

if (any(inf <- is.infinite(w))) x[inf]

else weighted.mean(x, w)

in your own code.

Duncan Murdoch

*> Cheers
**>
**> Yan
**>
*

> p.s. a while ago I suggested using '??xxx' as a shortcut for

*> help.search("xxx"), much like '?xxx' is a shortcut for help("xxx"). I
**> was just wondering if anyone had any more thoughts on the matter?
*

Suggestions like this (and probably the one above) belong more in the
R-devel list than here. I think your ?? suggestion is reasonable; why
don't you write up the necessary patch to implement it, and see if it's
feasible? Include that in your post to R-devel, and it will be easier
for others to see the pitfalls (if there are any).

Duncan Murdoch

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 11 23:00:24 2006

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.1.8, at Sat 12 Aug 2006 - 06:20:14 EST.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*