How do I create a POSIXct date from the date and time parts below
date<-as.Date("2014-01-01")
hour<-5
minute<-15
second<-59
millisecond<-695
date
hour
minute
second
millisecond
output should be a POSIXct object
2014-01-01 05:15:59.695
How do I create a POSIXct date from the date and time parts below
date<-as.Date("2014-01-01")
hour<-5
minute<-15
second<-59
millisecond<-695
date
hour
minute
second
millisecond
output should be a POSIXct object
2014-01-01 05:15:59.695
The following should do it: First set options to be able to display milliseconds
options(digits.secs=3)
Next paste the date elements to form a date string
date_string <- paste(date, paste(paste(hour,minute,second,sep=":"),millisecond,sep="."),sep = " ")
Then convert to a POSIXct object
as.POSIXct(date_string,tz="",format="%Y-%m-%d %H:%M:%OS")