R 折叠包:将函数应用于列表或原子向量的每个元素
我正在切换到 collapse
R
包以获得更好的速度。但是,我正在努力将 purrr::map 及其变体转换为 collapse 代码。无法弄清楚如何将 1:2 %>% map(.x = ., .f = rnorm, n = 3)
转换为相关的 collapse
代码。我的尝试如下:
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"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论