ifilter {itertools} | R Documentation |
Create a filtering iterator
Description
The ifilter
and ifilterfalse
functions create iterators
that return a subset of the values of the specified iterable.
ifilter
returns the values for which the pred
function
returns TRUE
, and ifilterfalse
returns the values for
which the pred
function returns FALSE
.
Usage
ifilter(pred, iterable)
ifilterfalse(pred, iterable)
Arguments
pred |
A function that takes one argument and returns |
iterable |
The iterable to iterate over. |
Examples
# Return the odd numbers between 1 and 10
as.list(ifilter(function(x) x %% 2 == 1, icount(10)))
# Return the even numbers between 1 and 10
as.list(ifilterfalse(function(x) x %% 2 == 1, icount(10)))
[Package itertools version 0.1-3 Index]