« Scraping a website with 5 lines of R code | Main | Because it's Friday: Excel Painter »

January 25, 2018

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Using

anydup <- function(ignored = NULL) {
s <- sample.int(length(bdays), n, replace = TRUE, prob = probs)
a <- anyDuplicated.default(s)
as.logical(a != 0L)
}

loop should be around 4 times faster.

Thanks @minem. I'm sure there are lots of ways to speed up that code -- the easiest would be to use pbirthday() directly. You can also get a good estimate with way fewer than 100k simulations. But in this case it was useful to me for it to be slower rather than faster: it made it easier to show the changes when you go parallel. :)

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)

Search Revolutions Blog




Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid
Get this blog via email with Blogtrottr