Écrire du code R efficace
Colin Gillespie
Jumping Rivers & Newcastle University
library("parallel")
apply() est semblable à une boucle for
Une matrice de 10 colonnes et 10 000 lignes :
m <- matrix(rnorm(100000), ncol = 10)
res <- apply(m, 1, median)
parApply()library("parallel")
copies_of_r <- 7
cl <- makeCluster(copies_of_r)
parApply(cl, m, 1, median)
stopCluster(cl)
Comme l'a dit Lewis Caroll
The hurrier I go, the behinder I get.
# Version sérielle
apply(m, 1, median)
# Version parallèle
parApply(cl, m, 1, median)
Écrire du code R efficace