Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rounding up the time expression in R

I have a data Y . Y has a column time .
time column looks like this:

enter image description here

For example, 20211201000010 means 2021-12-01 00:00:10 .

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

time <- strptime(Y$time, format = "%Y%m%d%H%M%S")

start_time <- min(time)

In this code, start_time is 2021-12-01 00:00:02.

But I want to round up the start_timeas 2021-12-01 00:00:10,since the start_time should be 10 seconds interval for my data.

How can I round up 2021-12-01 00:00:02 as 2021-12-01 00:00:10 ?

>Solution :

lubridate package is always our friends for datetime work.


library(lubridate)      
xx1 <- '20211201010002'

ymd_hms(xx1) %>%
  ceiling_date(unit = '10s')

[1] "2021-12-01 01:00:10 UTC"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading