How to round up to whole number in R?

66,954

We can use ceiling to do the specified rounding

ceiling(x)
#[1]  6  8 13 14
Share:
66,954
user2716568
Author by

user2716568

Updated on April 21, 2021

Comments

  • user2716568
    user2716568 about 3 years

    Is it possible to round up to the nearest whole number in R? I have time-stamped data and I want to round up to the nearest whole minute, to represent activities during this minute.

    For example, if time is presented in minutes.seconds format:

    x <- c(5.56, 7.39, 12.05, 13.10)
    round(x, digits = 0)
    [1]  6  7 12 13
    

    My anticipated output would instead be:

    round(x, digits = 0)
    [1]  6  8 13 14
    

    I understand this is confusing but when I am calculating activity per minute data, rounding up to the nearest minute makes sense. Is this possible?