Can purrr simulate random walks in fewer lines of code than the R base?
For example, what does the following look like in purrr ?
n <- 5 x <- numeric(n) for(i in 2:n){ x[i] <- x[i-1] + rnorm(1) }
Edit: @ I had what I was looking for. To take this step further, I assume that a random walk can be created and built using the following code
tibble(x = 1:1000, y = cumsum(rnorm(1000, mean = 0))) %>% ggplot(aes(x=x,y=y))+ geom_point()+ geom_line()

r purrr
Alex
source share