r - Is it possible to have zip iterator (i.e. "zip" two iterators together) in foreach? -


i have 2 objects of equal length (one list produced parsing json, , slice of multi-dimensional of array), e.g.:

library(rjson) library(foreach) iter1<-iter( fromjson(file=jsonfilename)$somejsonarray ) iter2<-iter( myarr, by="row" ) 

i need able following:

out=foreach(x=zipiter(iter1,iter2),combine=list) %do% {     #do stuff elements both iterators accessed e.g. x[[1]] , x[[2]] } 

is there standard way of doing (like in python/c++ boost zip iterator)?

there izip function in itertools package describe:

library(itertools) out <- foreach(x=izip(iter1, iter2)) %do% {     # x[[1]] contains value iter1     # x[[2]] contains value iter2 } 

but prefer specify multiple loop variables foreach:

out <- foreach(x=iter1, y=iter2) %do% {     # x contains value iter1     # y contains value iter2 } 

both solutions iterate on values iterators in parallel. if want 2 arguments in list, izip more convenient.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -