R function sample()
Returns a random sample from a population. Called with three arguments: sample(dataSource, size=16, replace=TRUE) Can be nested as in: mean(sample(Population$V1, size=15, replace=TRUE)
What does the parameter replace do?
Let's first create a random function that will return an integer between two provided values (both inclusive). So, if you call random() with no parameters, it will behave just like Math.random(), but if you call with random(0, 12), then it will have an equally likely chance of returning 0, 1, 2,..., 12.
Have created a random(a, b) function and committed with the range() and median() functions. However I have not made tests for the random() function as I am not sure how to test that.
random = (a, b) ->
unless a? and b?
randnum = Math.random()
return randnum
else
min = a
max = b
randnum = Math.floor(Math.random() * (max - min + 1) + min)
return randnum
I have tested this in the console and it seems to work well. both a and b are inclusive and can be included as a random number.
Replace = TRUE means once you've drawn a random number from the sample, that number gets placed back into the sample and can be drawn again. Say you have a set {1, 2, 3, 4, 5} and draw 3. Without replacement, the next time you would draw from {1, 2, 4, 5}. With replacement, you would draw from {1, 2, 3, 4, 5}.
On Sun, Jun 16, 2013 at 8:18 PM, Larry Maccherone [email protected]:
What does the parameter replace do?
— Reply to this email directly or view it on GitHubhttps://github.com/lmaccherone/Lumenize/issues/45#issuecomment-19521785 .