Iterator Loop in R
An
iterator is a special type of object that generalizes the notion of a looping
variable. When passed as an argument to a function that knows what to do with
it, the iterator supplies a sequence of values. The iterator also maintains
information about its state, in particular its current index
# Simple
i1 <- iter(1:3)
nextElem(i1)
[1] 1
nextElem(i1)
[1] 2
nextElem(i1)
[1] 3
# vector iterator
i1 <- iter(1:3,
checkFunc=function(i) i %% 2 == 0)
nextElem(i1)
[1] 2
Note
: For Iterator install-> library(iterators)
Iterator Loop in R
Reviewed by Rupesh
on
05:02
Rating:
No comments: