R/weighted.median.R

Defines functions `weighted.median`

`weighted.median` <-
function(y, w)
{
  ox <- order(y)
  y <- y[ox]
  w <-w[ox]
  k <- 1
  low <- cumsum(c(0,w))
  up <- sum(w)-low
  df <- low-up
  repeat {
	 if (df[k] < 0) k<-k+1
	   	else if (df[k] == 0) return((w[k]*y[k]+w[k-1]*y[k-1])/(w[k]+w[k-1]))
	   		else return(y[k-1])
	}
}

Try the isotone package in your browser

Any scripts or data that you put into this service are public.

isotone documentation built on March 7, 2023, 6:58 p.m.