To find: a function object f, such that f(x) = y
Solution:
x <- c(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
y <- c(1, 2, 3, 4, 5, 6, 7, 10, 9, 8)
get_top <- function(x,n) ceiling(quantile(x, probs = n))
make_vct <- function(x,n) {
c(
sort(x[x < ceiling((get_top(x,.7)))]),
x[x >= ceiling((get_top(x,.7)))])
}
make_vct(x,.7)
#> [1] 1 2 3 4 5 6 7 10 9 8
Created on 2020-09-27 by the reprex package (v0.3.0.9001)