10.3.7.1 ore.indexApply関数の簡単な使用例

この例では、ore.indexApplyをコールし、入力関数を並行して5回実行することを指定します。

例10-12 ore.indexApply関数の使用方法

この例では、結果のクラスであるore.listを表示した後に、結果を表示します。

%r

computeMean <- function(index){
    set.seed(index)
    x <- round(runif(100,2,10),4)
    return(mean(x))
}

ore.indexApply(12, computeMean)

出力は、次のようなものです。

$`1`
6.142776
$`2`
5.932833
$`3`
5.872673
$`4`
6.383635
$`5`
6.147493
$`6`
6.251832
$`7`
6.07391
$`8`
5.981312
$`9`
5.927451
$`10`
5.562602
$`11`
5.320832
$`12`
5.837725

この例のリスト

R> res <- ore.indexApply(5,
+       function(index) {
+         paste("IndexApply:", index)
+       },
+       parallel = TRUE)
R> class(res)
[1] "ore.list"
attr(,"package")
[1] "OREembed"
R> res
$`1`
[1] "IndexApply: 1"
 
$`2`
[1] "IndexApply: 2"
 
$`3`
[1] "IndexApply: 3"
 
$`4`
[1] "IndexApply: 4"
 
$`5`
[1] "IndexApply: 5"