如何从speedDistribution
函数调用全局函数parLapply
?
speedDistribution <- function(speed)
{
return(quantile(speed, seq(0.2, 1, by = 0.20)))
}
estimateFeatures <- function(trips,target)
{
cl <- makeCluster( 4 )
features = NULL
features = parLapply(cl, 1:length(trips), function(z){
z <- as.data.frame(z)
speed <- 3.6 * sqrt(diff(z$x)^2 + diff(z$y)^2)
s <- speed[!speed > mean(speed) + sd(speed) * 5]
features = c(speedDistribution(s),target)
return(cbind(features, rep(z, nrow(features))))
})
stopCluster(cl)
return(features)
}
checkForRemoteErrors(val)出错:4个节点产生错误;第一 错误:找不到功能“speedDistribution”
答案 0 :(得分:2)
您需要使用clusterExport
功能导出所有工作人员可以使用的功能。添加:
clusterExport(cl, "speedDistribution")
在您尝试计算之前。