powered by
Remove duplicate elements, given a transformation.
unique_by(x, f, first = TRUE)
a vector or a list.
a function to apply to each element of x. This function must produce comparable results.
x
if several elements are identical after being transformed by f, keep the first. Otherwise, keep the last.
f
An object of the same type as x. Only elements that are unique after being transformed by f are kept.
# NOT RUN { unique_by(-3:2, abs) unique_by(-3:2, abs, first = FALSE) unique_by(c(1, 2, 4, 5, 6), function(x) x %% 3) unique_by(list(1:2, 2:3, 2:4), length) # }
Run the code above in your browser using DataLab