I have a vector of POSIXct objects, I would like to determine the first and the last date/time value in the list.
POSIXct_vector <- read.csv(file="data", as.is=TRUE)
POSIXct_vector$DateTime <- as.POSIXct(POSIXct_vector)
#returns NA
min(POSIXct_vector$DateTime)
#returns NA
max(POSIXct_vector$DateTime)
I suspect you need to add the na.rm=TRUE
argument to your commands. This also means that at least one of the elements of your vector hasn't been resolved to a valid time. You can also use range
to give the limits in one command.
dat <- as.POSIXct(rnorm(10,sd=1e6),origin=Sys.Date())
range(dat)
[1] "2011-07-25 12:36:23 BST" "2011-09-11 20:02:20 BST"
dat[3] <- NA
range(dat)
[1] NA NA
range(dat,na.rm=TRUE)
[1] "2011-08-02 06:42:05 BST" "2011-09-11 20:02:20 BST"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With