tidyverse / funs

Collection of low-level functions for working with vctrs
Other
34 stars 7 forks source link

group_map(x, g, f) #42

Open hadley opened 4 years ago

hadley commented 4 years ago

Something like this:

group_map <- function(g, x, f, ..., .ptype = NULL) {
  out <- vec_init(list(), length(g))
  for (i in seq_along(g)) {
    out[[i]] <- f(x[g[[i]]], ...)
  }
  vec_c(!!!out, .ptype = .ptype)
}

Most important would be to have a C++ version that would avoid allocation of intermediate vectors, assigning scalars directly into out. Probably could get away with just providing int and double versions for now.

lionel- commented 3 years ago

Does this belong in purrr instead?