[R] Date Time Conversion

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Wed May 8 17:30:15 CEST 2019


Hello,

as.Date() outputs an object of class "Date", you want an object of class 
c("POSIXt", "POSIXct"). Use as.POSIXct().

Hope this helps,

Rui Barradas

Às 16:04 de 08/05/19, reichmanj using sbcglobal.net escreveu:
> r-Help Community
> 
>   
> 
> I need to convert a date-time field (column)  but I'm losing the time  when
> I convert using  ..
> 
>   
> 
> tsData <- myData[,10, drop=FALSE]
> 
> tsData$date_time <- as.Date(tsData$date_time, format="%m/%d/%y %H:%M")
> 
> head(tsData)
> 
>   
> 
> 
>   
> 
>   
> 
> date_time
> 
> <date>
> 
> 	
> 
> 1
> 
> 2013-06-20
> 
> 	
> 
> 2
> 
> 2013-06-20
> 
> 	
> 
> 3
> 
> 2013-06-20
> 
> 	
> 
> 4
> 
> 2013-06-20
> 
> 	
> 
> 5
> 
> 2013-05-30
> 
> 	
> 
> 6
> 
> 2013-06-20
> 
> 	
> 
>   
> 
> R is doing what I'm asing it to do so I'm obviously using the wrong command.
> How do I convert, retaining the time
> 
>   
> 
> Sincerely
> 
>   
> 
> Jeffery (Jeff) Reichman
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list