润滑未将R中的日期时间正确转换为POSIXct(dd/mm/yy hh:mm:ss) [英] Lubridate not converting datetime to POSIXct correctly in R (dd/mm/yy hh:mm:ss)
本文介绍了润滑未将R中的日期时间正确转换为POSIXct(dd/mm/yy hh:mm:ss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将日期时间从csv转换为POSIXct,以进行数据分析.我尝试了多种代码,但是得到的结果不正确或格式错误.
I'm trying to convert my datetime from a csv to POSIXct for data analysis. I've tried multiple codes but either get NA or a wrong format.
我当前使用的代码是
GRS$datetimelocal<-
GRS$`datetime` %>%
ymd_hms(tz="UTC") %>% # first convert the `Date and Time (UTC)`
column into a 'POSIX' format
with_tz(tzone="Australia/Brisbane") # convert to local
"Australia/Brisbane" date time (UTC + 10hrs)
我的datetime列的格式为dd/mm/yy hh:mm:ss.
My datetime column is in the format dd/mm/yy hh:mm:ss.
datetime
26/03/2013 21:50
26/03/2013 21:56
26/03/2013 21:58
28/03/2013 07:42
但是新列显示为
datetimelocal
2026-03-20 13:21:50
2026-03-20 13:21:56
2026-03-20 13:21:58
2028-03-20 13:07:42
任何帮助将不胜感激
推荐答案
为什么不直接使用 as.POSIXct
?
as.POSIXct("26/03/2013 21:50",
format = "%d/%m/%Y %H:%M",
tz = "Australia/Brisbane")
## [1] "2013-03-26 21:50:00 AEST"
这篇关于润滑未将R中的日期时间正确转换为POSIXct(dd/mm/yy hh:mm:ss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文