[R] Building a random walk vector

Ben Bolker bolker at ufl.edu
Fri Aug 4 03:27:22 CEST 2006


Matthew Wilson <matt <at> overlook.homelinux.net> writes:

> 
> I'm studying R in my free time.  I want to build a vector where each
> element is equal to the element before it in the sequence plus some
> random tweak.
> 

  You will probably get many answers to this, but
I think

vec <- 100+c(0,cumsum(runif(49,-2,2)))

works.

  Ben Bolker



More information about the R-help mailing list