Iterators — object-oriented programming constructs that act as a pointer in an ordered sequence — are familiar to programmers of languages like Python, but are not a standard part of the R language. Nonetheless, by installing the iterators package (an open-source contribution by Revolution Analytics) you can create and manipulate iterator objects in R.

If you're new to iterators, Exegetic Analytics provides an in-depth tutorial on iterators in R, with worked examples of using iterators to:

- loop over rows/columns of matrices and data frames
- iterate over lines in a file
- filter a sequence (say, to select only primes)
- create custom iterators to generate sequences (e.g. the Fibonacci sequence)

In addition to providing a more elegant was to program with sequences, iterators in R also make it easy to parallelize R code using the foreach package.

Exegetic Analytics: Iterators in R

*Related*

To

**leave a comment** for the author, please follow the link and comment on his blog:

** Revolutions**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as: visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...