Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:16:40+00:00 2026-06-12T08:16:40+00:00

Yes I know why we always round to the nearest even number if we

  • 0

Yes I know why we always round to the nearest even number if we are in the exact middle (i.e. 2.5 becomes 2) of two numbers. But when I want to evaluate data for some people they don’t want this behaviour. What is the simplest method to get this:

x <- seq(0.5,9.5,by=1)
round(x)

to be 1,2,3,…,10 and not 0,2,2,4,4,…,10.

Edit: To clearify: 1.4999 should be 1 after rounding. (I thought this would be obvious)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:16:41+00:00Added an answer on June 12, 2026 at 8:16 am

    This is not my own function, and unfortunately, I can’t find where I got it at the moment (originally found as an anonymous comment at the Statistically Significant blog), but it should help with what you need.

    round2 = function(x, digits) {
      posneg = sign(x)
      z = abs(x)*10^digits
      z = z + 0.5 + sqrt(.Machine$double.eps)
      z = trunc(z)
      z = z/10^digits
      z*posneg
    }
    

    x is the object you want to round, and digits is the number of digits you are rounding to.

    An Example

    x = c(1.85, 1.54, 1.65, 1.85, 1.84)
    round(x, 1)
    # [1] 1.8 1.5 1.6 1.8 1.8
    round2(x, 1)
    # [1] 1.9 1.5 1.7 1.9 1.8
    

    (Thanks @Gregor for the addition of + sqrt(.Machine$double.eps).)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes I know, this title isn't really helpfull but this is the exact problem.
yes I know it's unusual, but I actually want to turn of intellisense for
(Yes I know I can call Java code from Scala; but that is pointless;
I have the following code (Yes I know it's quite long winded, but I
I want to develop a web application, like an online scheduler. (Yes I know
i think i sort of know the answer to this, but there are always
Yes, I know there's Voter tutorial in cookbook . But I'm looking for something
Yes I know that it shouldn't be abused and that C# is primariy used
Ok so I start coding websites (yes I know I am almost 15 years
I´m trying to code a tooltip (Yes I know, I have my reasons to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.