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

Range of Timestamps

I’ve got two datasets, both datasets have similar timestamps.
When I print the range (with range() ) for the first dataset, I get the range of timestamps without problems. But when I do it for the second timestamp, I get "NA, NA". This is the format of the second dataset:
format

Am I missing something?

Kind regards,
Daniel

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

>Solution :

This is likely due to there being one or more NA values in your second data set. Even a single NA will cause the output of range to be c(NA ,NA), as we can see in this toy example:

x  <- as.POSIXct(c("2020-01-01 20:00:00", 
                   "2020-01-02 20:00:00", 
                   "2020-01-03 20:00:00"))

range(x)
#> [1] "2020-01-01 20:00:00 GMT" "2020-01-03 20:00:00 GMT"

x[2] <- NA

range(x)
#> [1] NA NA

The solution is to use the na.rm argument in range:

range(x, na.rm = TRUE)
#> [1] "2020-01-01 20:00:00 GMT" "2020-01-03 20:00:00 GMT"

Created on 2022-01-27 by the reprex package (v2.0.1)

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