How to parallelize rollapply?

40 views Asked by At

I would like to parallelize the following rollapply in order to make it faster:

Function for rollapply

euclidiansum <- function(x) sum(((standardize(x[,"Passenger.x"]) - standardize(x[,"Passenger.y"]))^2)) 

Calculation

tidyverse_rolling_euclidian <- pairwise_combos %>%
group_by(vehiculetype) %>%
tq_mutate(mutate_fun = rollapply,
          width      = 50,
          FUN        = euclidiansum,
          by.column  = FALSE,
          col_rename = "Euclidiansum")

Example data (very reduced example)

df <- read.table(text = "
vehiculetype,  Passenger.x, Passenger.y
  1,  400,  700
  2, 420, 100
 2, 210, 300
 2,  100,  100
  2,  400, 100
 1,  800, 70
 1,  300, 40
  1,  10, 200
  1, 50,  10
 2, 90,  30",
sep = ",", header = TRUE)

Do you know how I can speed up the calculation?

Thank you very much.

0

There are 0 answers