[R] Assignment Operator in mclapply
Dario Strbenac
d.strbenac at garvan.org.au
Tue Feb 26 05:01:27 CET 2013
I sometimes need to return multiple items from a loop. Is it possible to have the <<- operator work the same for mclapply as for lapply ?
> extra <- list()
> squares <- mclapply(1:10, function(x){extra[[x]] <<- x; x^2;})
> extra
list()
> squares <- lapply(1:10, function(x){extra[[x]] <<- x; x^2;})
> extra
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 4
[[5]]
[1] 5
[[6]]
[1] 6
[[7]]
[1] 7
[[8]]
[1] 8
[[9]]
[1] 9
[[10]]
[1] 10
My question is like that of http://tolstoy.newcastle.edu.au/R/e6/help/09/03/8329.html which is not answered.
--------------------------------------
Dario Strbenac
PhD Student
University of Sydney
Camperdown NSW 2050
Australia
More information about the R-help
mailing list