Extracting entries in a dataframe corresponding to n smallest positive values and n largest negative values of a certain variable in r Imagine I have a table like the following one.