split_by {purrr} | R Documentation |
Split, order and sort lists by their components.
split_by(.x, .f, ...) order_by(.x, .f, ...) sort_by(.x, .f, ...)
.x |
A list or atomic vector. |
.f |
A function, formula, or atomic vector. If a function, it is used as is. If a formula, e.g. If character or integer vector, e.g. |
... |
Additional arguments passed on to |
l1 <- transpose(list(x = sample(10), y = 1:10)) l1 l1 %>% order_by("x") l1 %>% sort_by("x") l2 <- rerun(5, g = sample(2, 1), y = rdunif(5, 10)) l2 %>% split_by("g") %>% str() l2 %>% split_by("g") %>% map(. %>% map("y"))