{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Week 6 Feb 8.pdf - Week 6 Feb 8 Wednesday 12:23 PM Random...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
runif(# of numbers, lower bound = 0, upper bound = 1) Random numbers actually repeat after a certain number of periods (pseudo-random) same "random" numbers will pop up if you set seed before running runif Set seed (set.seed) so you can reproduce results if needed sample(max number) creates line of mumbers 0- max in random order Random Numbers data + runif (# of data elements, -0.5, +0.5) Helps see points that may be overlapping on graph Jitter f <- function() { if(runif(1)<0.15) { print("u ded") } else if (runif(1) < 0.4) { print("u lucky") } else { print("zinger") } } Random numbers at work: position <- numeric(steps+1) position[i+1] <- position[i] + 1 if (runif(1) < 0.5) else position[i+1] <- position[i] - 1 for (i in 1:steps) { } position random_walk <- function (steps) { } "Random Walk" Exist only within a function, not console as a whole l s() allows you to see all defined variables in an environment rm(var) removes a variable print (abc) # refers to the global variable ’abc’ print (xyz) # refers to the local variable (argument) 'xyz'
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}