Dirk Eddelbuettel — written Jan 1, 2013 — source
The STL contains a very general looping or sweeping construct in
the for_each
algorith. It can be used with function objects
(such as the simple square
function used here)
but also with custom class which can be used to keep to keep state.
We can illustrate this on a simple example:
[1] 0.013710 -0.005647 0.003631 0.006329 0.004043 -0.001061
Iteration 1 Growth 0.0137096 Compounded 1.01371 Proportion 1 Iteration 2 Growth -0.00564698 Compounded 1.00799 Proportion -0.707182 Iteration 3 Growth 0.00363128 Compounded 1.01165 Proportion 0.31182 Iteration 4 Growth 0.00632863 Compounded 1.01805 Proportion 0.350659 Iteration 5 Growth 0.00404268 Compounded 1.02216 Proportion 0.182403 Iteration 6 Growth -0.00106125 Compounded 1.02108 Proportion -0.0503469
tags: stl
Tweet