sortf {baizer} | R Documentation |
sort by a function
Description
sort by a function
Usage
sortf(x, func, group_pattern = NULL)
Arguments
x |
vector |
func |
a function used by the sort |
group_pattern |
a regex pattern to group by, only available if x is a character vector |
Value
vector
Examples
sortf(c(-2, 1, 3), abs)
v <- stringr::str_c("id", c(1, 2, 9, 10, 11, 12, 99, 101, 102)) %>% sample()
sortf(v, function(x) reg_match(x, "\\d+") %>% as.double())
sortf(v, ~ reg_match(.x, "\\d+") %>% as.double())
v <- c(
stringr::str_c("A", c(1, 2, 9, 10, 11, 12, 99, 101, 102)),
stringr::str_c("B", c(1, 2, 9, 10, 21, 32, 99, 101, 102))
) %>% sample()
sortf(v, ~ reg_match(.x, "\\d+") %>% as.double(), group_pattern = "\\w")
[Package baizer version 0.8.0 Index]