Learn R Programming

CNprep (version 1.0)

weighted.median:

Usage

weighted.median(v, weights)

Arguments

v
weights

Value

    Examples

    Run this code
    ##---- Should be DIRECTLY executable !! ----
    ##-- ==>  Define data, use random,
    ##--	or do  help(data=index)  for the standard data sets.
    
    ## The function is currently defined as
    function (v, weights) 
    {
        weights <- weights[order(v)]
        v <- sort(v)
        sw <- sum(weights)
        return(v[order(abs(cumsum(weights) - 0.5 * sw))][1])
      }

    Run the code above in your browser using DataLab