Learn R Programming

eeptools (version 0.3.1)

thresh: function to return the maximum percentage of the cumulative sum represented by a subset of the vector

Description

Returns the proportion of the cumulative sum represented by the number of elements in the vector a user specifies. This allows the user to identify the maximum proportion of the total that only X number of elements may represent in the vector.

Usage

thresh(x, cutoff)

Arguments

x
a numeric vector, missing values are allowed
cutoff
the number of elements to look at

Value

  • An integer for the proportion of the vector's sum reached at cutoff

See Also

cutoff which this function is related to

Examples

Run this code
# for vector
a<-rnorm(100,mean=6,sd=1)
thresh(a,8) #return minimum number of elements to account 70 percent of total
# for df

## The function is currently defined as
function (x, cutoff) 
{
    x <- x[order(-x)]
    xb <- cumsum(x)
    xc <- xb/sum(x, na.rm = T)
    xc[cutoff]
  }

Run the code above in your browser using DataLab