1:3 %>% accumulate(`+`)
1:10 %>% accumulate_right(`*`)
# From Haskell's scanl documentation
1:10 %>% accumulate(max, .init = 5)
# Simulating stochastic processes with drift
## Not run:
# library(dplyr)
# library(ggplot2)
#
# rerun(5, rnorm(100)) %>%
# set_names(paste0("sim", 1:5)) %>%
# map(~ accumulate(., ~ .05 + .x + .y)) %>%
# map_df(~ data_frame(value = .x, step = 1:100), .id = "simulation") %>%
# ggplot(aes(x = step, y = value)) +
# geom_line(aes(color = simulation)) +
# ggtitle("Simulations of a random walk with drift")
# ## End(Not run)
Run the code above in your browser using DataLab