h = max{dk(l), hmin}, where dk(l) is the distance from l to the 70th nearest li and hmin=1000.
Hello, I want to have in output a vector when the entry is vector for this function.
I want l,li and yi in entries, so I can calcultef1(L,li=position,yi=y) with differents vectors for li and yi. Let's consider only this vectors for yi and li for example:
y <- seq(1, 100, length.out = 23710)
position <- seq(10351673, 12422082, length.out=23710)
L <- seq(11190000, 11460000, by=10)
With help of @jblood94 I got this
library(parallel)
f1 <- function(l) {
dkAll <- abs(outer(position, l, "-"))
Knorm <- dnorm(outer(position, l, "-")/pmax(dkAll[order(col(dkAll), dkAll)[seq(70, by = length(position), length.out = length(l))]], 1000))
colSums(Knorm*y)/colSums(Knorm)
}
y <- seq(1, 100, length.out = 23710)
position <- seq(10351673, 12422082, length.out=23710)
l <- seq(11190000, 11460000, by=10)
# ysmoothed <- f1(l) # memory allocation error
cl <- makeCluster(detectCores())
clusterExport(cl, list("y", "position", "l", 'f1'))
system.time(ysmoothed <- parLapply(cl, l, f1))
#> user system elapsed
#> 0.02 0.00 20.13
This function works correctly. The purpose is to rewrite with three entries and avoid error Error in get(name, envir = envir) : object 'y' not found by using the command clusterExport(cl, list("y", "position", "l", 'f1')) .
I hope @jblood94 will see my message!
