Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round up to whole number in R?

Tags:

rounding

r

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?

like image 785
user2716568 Avatar asked Apr 17 '17 03:04

user2716568


People also ask

How do I round an entire column in R?

Round function in R, rounds off the values in its first argument to the specified number of decimal places. Round() function in R rounds off the list of values in vector and also rounds off the column of a dataframe. It can also accomplished using signif() function.

How do I round to .5 in R?

round rounds the values in its first argument to the specified number of decimal places (default 0). Note that for rounding off a 5, the IEEE standard is used, ``go to the even digit''. Therefore round(0.5) is 0 and round(-1.5) is -2 .

How do you round to the nearest 100 in R?

Roundup or round down numbers in RTo round up, use ceiling, and to round down, use the floor. Both functions round to the nearest integer but in a different direction.


1 Answers

We can use ceiling to do the specified rounding

ceiling(x)
#[1]  6  8 13 14
like image 107
akrun Avatar answered Oct 11 '22 17:10

akrun