Skip to contents

Fisher's circular median: the direction minimising the summed angular distance to every observation. Where two directions tie, their mean direction is returned.

Usage

circ_median(x, na_rm = TRUE)

Arguments

x

A numeric vector of angles, in radians, in any range.

na_rm

A logical value (default TRUE) determining whether missing values are removed before computing. When FALSE, any NA gives NA.

Value

A single angle in (-pi, pi], or NA_real_ when there is nothing to summarise.

Details

The median is signed, in (-pi, pi], the range the suite uses for every direction (see wrap_angle()), so it can be compared directly with the angles it summarises. Wrap it with wrap_angle(x, "2pi") for [0, 2*pi).

Examples

# a little below zero, not a little below 2 * pi
circ_median(c(-0.1, -0.2, 0.05))
#> [1] -0.1

# unaffected by where the circle is cut
circ_median(c(0.1, 0.2, 6.2))
#> [1] 0.1
circ_median(c(0.1, 0.2, 6.2) + pi)
#> [1] -3.041593