[R] (no subject)

Duncan Murdoch dmurdoch at pair.com
Wed Aug 20 22:42:24 CEST 2003


On Wed, 20 Aug 2003 19:37:59 +0100, Martin Biuw
<emb7 at st-andrews.ac.uk> wrote :

>Hello,
>Is there a simple way to modify the circ.mean function in the CircStats 
>package to include a vector of weights to obtain a weighted average angle?

This should do it:

circ.weighted.mean <- function (x,w) 
{
    sinr <- sum(w*sin(x))
    cosr <- sum(w*cos(x))
    circmean <- atan(sinr, cosr)
    circmean
}

I was surprised that atan worked with 2 arguments; it's documented to
use only 1.  According to the docs, you're supposed to use atan2 if
you want the two argument arctangent.

Duncan Murdoch




More information about the R-help mailing list