Last chance! 50% off unlimited learning
Sale ends in
psel(df, pref, ...)
psel.indices(df, pref, ...)
complex_pref
and base_pref
.
All variables occuring in the definition of pref
must be either columnstop
value "k" the k best elements and their level values are returned. The level values are determined as follows:
df
psel
it is also possible to perform a preference selection where the maxima are calculated for every group seperately.
The groups have to be created with group_by
from the dplyr package. The preference selection preserves the grouping, i.e.,
the groups are restored after the preference selection.
For example the summarize
function from dplyr refers to the set of maxima of each group.
This can be used to e.g. calculate the number of maxima in each group, see examples below.
A {top, at_least, top_level} preference selection is applied to each group seperately.
A top=k
selection returns the k best tuples for each group.
Hence if there are 3 groups in df
, each containing at least 2 elements,
and we have top = 2
then 6 tuples will be returned.options(rPref.parallel = FALSE)
If this option is not set, rPref will use parallel computation by default.psel
function returns a subset of the dataset which are the maxima according to the given preference.psel.indices
returns just the row indices of the maxima
(except Top-k queries withshow_level = 1
, see Top-k preference selection).
Hencepsel(df,pref)
is equivalent todf[psel.indices(df,pref),]
for non-grouped dataframes.complex_pref
on how to construct a Skyline preference. See plot_front
on how to plot the pareto front of a Skyline# Skyline and Top-K/At-least skyline
psel(mtcars, low(mpg) * low(hp))
psel(mtcars, low(mpg) * low(hp), top = 5)
psel(mtcars, low(mpg) * low(hp), at_least = 5)
# Visualize the skyline in a plot
sky1 <- psel(mtcars, high(mpg) * high(hp))
plot(mtcars$mpg, mtcars$hp)
points(sky1$mpg, sky1$hp, lwd=3)
# Grouped preference with dplyr
library(dplyr)
psel(group_by(mtcars, cyl), low(mpg))
# Return size of each maxima group
summarise(psel(group_by(mtcars, cyl), low(mpg)), n())
Run the code above in your browser using DataLab