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

January 25, 2018


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


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. :)

The comments to this entry are closed.

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