Skip to content
R for the Rest of Us Logo

R doesn't round the way you think it does

I can't tell you how much time I've spent thinking about rounding in R. Rounding, you ask? Yep! Rounding in R can be confusing because the way R rounds numbers is different than what you might expect. Here's how it works!

Code shown in video

round(x = 11.5, digits = 0)
round(x = 12.5, digits = 0)

library(janitor)

round_half_up(x = 11.5, digits = 0)
round_half_up(x = 12.5, digits = 0)

Sign up for the newsletter

Get blog posts like this delivered straight to your inbox.

Let us know what you think by adding a comment below.

You need to be signed-in to comment on this post. Login.

David Keyes
By David Keyes
May 30, 2024

Sign up for the newsletter

R tips and tricks straight to your inbox.