R collapse package: apply a function to each element of a list or atomic vector

316 Views Asked by At

I'm switching to collapse R package for better speed. However, I'm struggling to translate purrr::map and its variants into collapse code. Couldn't figured out how to translate 1:2 %>% map(.x = ., .f = rnorm, n = 3) into relevant collapse code. My attempt is below:

library(tidyverse)
suppressMessages(library(collapse))

1:2 %>%
  map(.x = ., .f = rnorm, n = 3)
#> [[1]]
#> [1]  1.0567499  0.6074554 -0.5142574
#> 
#> [[2]]
#> [1] 2.369641 2.895773 1.256230


1:2 %>%
  rapply2d(l =., FUN = rnorm, n = 3)
#> [1] 1.613705 1.338446 1.404881

1:2 %>%
  rapply2d(l =., FUN = rnorm, 3)
#> [1] 4.082665 3.827381

1:2 %>%
  rapply2d(l =., FUN = rnorm(n = 3))
#> Error in FUN(y, ...): could not find function "FUN"
0

There are 0 best solutions below