본문 바로가기
언어/R

R foreach

by newlibra 2025. 3. 26.

 

 

https://www.spsanderson.com/steveondata/posts/2025-03-24/

 

How to Use the foreach() Function in R: A Comprehensive Guide – Steve’s Data Tips and Tricks

Unlock the power of parallel processing with the foreach() function in R! This comprehensive guide explores how to efficiently handle data analysis using foreach() with practical examples, best practices, and comparisons to traditional loops. Perfect for R

www.spsanderson.com

 

> numbers <- 1000000000 + 1:8
> source("seq.R")
Sequential: 0.012 sec elapsed
> source("seq.R")
Sequential: 0.012 sec elapsed

> source("seqP.R")
Parallel: 0.184 sec elapsed
> source("seqP.R")
Parallel: 0.17 sec elapsed
> source("seqP.R")
Parallel: 0.171 sec elapsed
> source("seqP.R")
Parallel: 0.162 sec elapsed
> source("seqP.R")
Parallel: 0.168 sec elapsed

> stopImplicitCluster()
> identical(seq_result, par_result)
[1] TRUE

 

tested the last example in my computer because the duration time is weired. Parallel job is  more slow !

(seq.R and  seqP.R are the same functions of the example. i just wrote in a file.)

'언어 > R' 카테고리의 다른 글

basic  (0) 2025.04.30
R statistics  (0) 2025.04.19
R BlackSholes  (0) 2025.02.19
엑셀파일 읽고 csv 파일 저장  (0) 2025.02.02
ggplot2  (0) 2025.01.28