Computes a weighted MAD of a numeric vector.

1 2 3 |

`x` |
a |

`w` |
a vector of weights the same length as |

`idxs, rows, cols` |
A |

`na.rm` |
a logical value indicating whether |

`constant` |
A |

`center` |
Optional |

`...` |
Not used. |

Returns a `numeric`

scalar.

Missing values are dropped at the very beginning, if argument
`na.rm`

is `TRUE`

, otherwise not.

Henrik Bengtsson

For the non-weighted MAD, see `mad`

.
Internally `weightedMedian`

() is used to
calculate the weighted median.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ```
x <- 1:10
n <- length(x)
m1 <- mad(x)
m2 <- weightedMad(x)
stopifnot(identical(m1, m2))
w <- rep(1, times=n)
m1 <- weightedMad(x, w)
stopifnot(identical(m1,m2))
# All weight on the first value
w[1] <- Inf
m <- weightedMad(x, w)
stopifnot(m == 0)
# All weight on the first two values
w[1:2] <- Inf
m1 <- mad(x[1:2])
m2 <- weightedMad(x, w)
stopifnot(identical(m1,m2))
# All weights set to zero
w <- rep(0, times=n)
m <- weightedMad(x, w)
stopifnot(is.na(m))
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.