Skip to content
Prev 27421 / 29559 Next

slow computation progress for calc function

Dear ?kos, 
I tried it on a small partition of my data. However, the processing time is the same :(. Any other suggestion? 

-------------------------
Sara Shaeri KarimiPhD Candidate, Department of Environmental SciencesFaculty of Science and EngineeringMacquarie University, NSW 2109 Australia?
Researchgate
Linkedin
On Tuesday, June 25, 2019, 4:33:34 PM GMT+10, Bede-Fazekas ?kos <bfalevlist at gmail.com> wrote:
Dear Sara,

it is faster if you first convert the integer vector to logical, and 
then run rle().

set.seed(12345)
random_sample <- sample.int(n = 10, size = 1e5, replace = TRUE) - 1

original <- function(x){
 ??? y <- rle(x)
 ??? return(max(y$lengths[y$values == 0]))
}

faster <- function(x){
 ??? y <- rle(x == 0)
 ??? return(max(y$lengths[y$values]))
}

original(random_sample) == faster(random_sample)

library(microbenchmark)
microbenchmark(
 ??? original(random_sample),
 ??? faster(random_sample)
)

Hence, this may be faster:
interflood <- clusterR(all_predictions, calc, args=list(function(x){y <- 
rle(as.numeric(x) == 0; return(max(y$lengths[y$values]))}))

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences

2019.06.25. 3:32 keltez?ssel, Sara Shaeri via R-sig-Geo ?rta:
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo