How to round to an integer in R?

Is it possible to round to the nearest integer in R? I have time-stamped data, and I want to round to the nearest whole minute to represent actions during that minute.

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

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

My expected result would look like this:

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

I understand that this is confusing, but when I calculate the activity per minute of data, rounding to the nearest minute makes sense. Is it possible?

+6
source share
1 answer

We can use ceilingto perform the specified rounding.

ceiling(x)
#[1]  6  8 13 14
+8
source

Source: https://habr.com/ru/post/1016579/


All Articles