Simulate random walk with purrr in R

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() 

enter image description here

0
r purrr
source share

No one has answered this question yet.

See similar questions:

8
Casual walking simulation

or similar:

137
Why use purrr :: map instead of lapply?
nine
Is there a function or package that will simulate predictions for an object returned from lm ​​()?
3
How to make geom_step play well with discrete coefficients along the y axis?
3
Simulation of a random value of a time series in R?
2
Difference between imitation () and forecast () in the β€œforecast” package
2
Modeling thousands of regressions and getting p values
2
Modeling from a linear mixed model with random intercepts
one
Creating folders using walk and purrr
0
purrr :: walk does not work as expected
0
ggplot does not show data in Shiny Plot (Warning: Deleted k lines containing missing values ​​(geom_point))

All Articles