Skip to content
Prev 385133 / 398502 Next

Double MAD with R

Dear Rui,

Many thanks for your response. 

Best,

SV







Le lundi 3 ao?t 2020 ? 16:54:35 UTC+2, Rui Barradas <ruipbarradas at sapo.pt> a ?crit : 





Hello,

No, there isn't a built-in that I know of.
Here is one:


double.mad <- function(x, include.right = FALSE, na.rm = FALSE){
? if(na.rm) x <- x[!is.na(x)]
? m <- median(x)
? odd <- (length(x) %% 2L) == 1L
? out <- if(odd){
??? if(include.right) {
????? c(lo = mad(x[x < m]), hi = mad(x[x >= m]))
??? } else {
????? c(lo = mad(x[x <= m]), hi = mad(x[x > m]))
??? }
? } else {
??? c(lo = mad(x[x < m]), hi = mad(x[x > m]))
? }
? out
}

double.mad(x)
#???? lo????? hi
#0.81543 0.44478

double.mad(c(x, 1))
#???? lo????? hi
#2.29803 0.44478

double.mad(c(x, 1), include.right = TRUE)
#???? lo????? hi
#1.03782 1.63086


Hope this helps,

Rui Barradas

?s 15:22 de 03/08/2020, varin sacha via R-help escreveu: