Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R function sample() #45

Open
jmaccherone opened this issue May 10, 2013 · 4 comments
Open

R function sample() #45

jmaccherone opened this issue May 10, 2013 · 4 comments
Assignees

Comments

@jmaccherone
Copy link
Collaborator

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)

@ghost ghost assigned coltoncockman Jun 17, 2013
@lmaccherone
Copy link
Owner

What does the parameter replace do?

@lmaccherone
Copy link
Owner

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.

@coltoncockman
Copy link
Contributor

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.

@jmaccherone
Copy link
Collaborator Author

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
notifications@github.comwrote:

What does the parameter replace do?


Reply to this email directly or view it on GitHubhttps://github.com//issues/45#issuecomment-19521785
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants