set.seed(12) sample(1:10) sample(c(-1,1), 1) steps.rw <- vector("numeric", length = 1000) steps.rw steps.rw[2] <- sample(c(-1,1), 1) head(steps.rw) steps.rw[3] <- steps.rw[2] + sample(c(-1,1), 1) steps.rw[4] <- steps.rw[3] + sample(c(-1,1), 1) steps.rw[5] <- steps.rw[4] + sample(c(-1,1), 1) steps.rw[3] <- steps.rw[2] + sample(c(-1,1), 1) steps.rw[3] <- steps.rw[2] + sample(c(-1,1), 1) steps.rw[3] <- steps.rw[2] + sample(c(-1,1), 1) steps.rw <- vector("numeric", length = 1000) for(i in 2:1000) { steps.rw[i] <- steps.rw[i-1] + sample(c(-1,1), 1) } steps.rw plot(steps.rw, type = "l") ##tady delam funkci random.walk <- function(no.steps) { steps.rw <- vector("numeric", length = no.steps) for(i in 2:no.steps) { steps.rw[i] <- steps.rw[i-1] + sample(c(-1,1), 1) } steps.rw } rw <- random.walk(no.steps = 2000) plot(rw, type = "l") par(mfrow=c(5,4), mar=rep(0.5,4)) for(k in 1:20) { plot(random.walk(2000)) }