R’s sample function works differently from R 3.6.0 onwards

Note to self:

From R 3.6.0, base R’s sample function works differently. This is to fix a bug in the previous version of the function (which caused some integers to be generated more often than others). A side effect of this is that simulations run with sample() before v3.6.0 will give different results from those run with >= v3.6.0.

For backward compatibility, you can add the following line to the top of the script:

RNGkind(sample.kind="Rounding")

To return sample‘s behavior to the v3.6.0 default, use the following line of code:

RNGkind(sample.kind="default")

More details from this Revolutions blog post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s