在问题here和here之后,我尝试让最新版本的multidplyr与自定义函数一起工作。
作为可重现的例子,我尝试了:
library(multidplyr)
library(dplyr)
cl <- new_cluster(3)
df <- data.frame(Grp = rep(LETTERS[1:3], each = 4), Val = rep(3:1, 4))
cust_func <- function (x) {
x + 1
}
cluster_copy(cl, "cust_func")
df_clust <- df %>%
group_by(Grp) %>%
partition(cl)
df_clust %>%
mutate(Add1 = cust_func(Val)) %>%
collect()但是我得到了一个Computation failed错误。我尝试了不同的排序和其他一些次要的变化,但没有成功。
在最新版本的multidplyr中,是否可以将自定义函数导出到集群中?如果是,是如何实现的?
发布于 2020-12-21 22:14:06
以下内容是否达到了您的预期?
new_cust_func <- function (x) {
x$Val + 1
return(x)
}
df_clust %>%
do(new_cust_func(.)) %>%
collect()https://stackoverflow.com/questions/60014692
复制相似问题