Imagine I have a table like the following one.
set.seed(12)
table =
data.frame(
value = rnorm(n = 10),
par = runif(n = 10, min = - 1, max = 1)
)
How can I extract the entries of value
and par
that correspond to the two smallest values of par
above zero and the two biggest ones below zero? What I would like to obtain is something like
out =
data.frame(
value = c(-0.2722960, -0.1064639, -0.3153487, 0.4280148),
par = c(-0.464112814, - 0.121141350, 0.009535904, 0.339638592)
)
I would appreciate if this could be done using dplyr
so to be able to do it for bigger dataframes with grouping variables.