Hi, I got the following R code and I need to convert it to python and run it in python environment, basically I have done this with rpy2 module, but it looks kind of dull with python doing the same things, so could someone find a better way to rewrite the following R code to an equivalent python script with the rpy2 module?
mymad <- function (x)
{
center <- median(x)
y <- abs(x - center)
n <- length(y)
if (n == 0)
return(NA)
half <- (n + 1)/2
1.4826 * if (n%%2 == 1) {
sort(y, partial = half)[half]
}
else {
sum(sort(y, partial = c(half, half + 1))[c(half, half +
1)])/2
}
}