Learn R Programming

PPLasso (version 2.0)

top: Thresholding to 0

Description

This function keeps only the K largest values of the vector and sets the others to 0.

Usage

top(vect, thresh)

Value

This function returns the thresholded vector.

Arguments

vect

vector to threshold

thresh

threshold

Author

Wencan Zhu, Celine Levy-Leduc, Nils Ternes

Examples

Run this code
x=sample(1:10,10)
thresh=3
top(x,thresh)

## The function is currently defined as
function(vect, thresh){
  sorted_vect <- sort(abs(vect),decreasing=TRUE)
  v<-sorted_vect[thresh]
  ifelse(abs(vect)>=v,vect,0)
}

Run the code above in your browser using DataLab