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
>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)