如何在R中舍入到整数?

时间:2022-09-02 23:21:28

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.

是否有可能在R中舍入到最接近的整数?我有时间戳数据,我想整理到最近的整分钟,以代表这一分钟内的活动。

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

例如,如果时间以minutes.seconds格式显示:

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?

我知道这很令人困惑但是当我计算每分钟活动数据时,四舍五入到最接近的分钟是有意义的。这可能吗?

1 个解决方案

#1


13  

We can use ceiling to do the specified rounding

我们可以使用ceiling来进行指定的舍入

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

#1


13  

We can use ceiling to do the specified rounding

我们可以使用ceiling来进行指定的舍入

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