[英]Date time conversion - from not standard to standard unambiguous format in R
I am currently working with a data set with a million rows where all of the dates are not in the standard unambiguous format that R requires.我目前正在处理一个包含一百万行的数据集,其中所有日期都不是 R 要求的标准明确格式。 I have worked on trying to reformat the date-time to the standard unambiguous format but have had zero luck.我一直在尝试将日期时间重新格式化为标准的明确格式,但运气为零。 I have tried using functions such as format
, as.POSIXlt
and as.POSIXct
but with no luck.我曾尝试使用诸如format
、 as.POSIXlt
和as.POSIXct
类的函数,但没有成功。
The format is currently "%m/%d/%Y %H:%M:%OS"
and I need to reformat it as "%Y/%m/%d %H:%M:%OS"
.当前格式为"%m/%d/%Y %H:%M:%OS"
,我需要将其重新格式化为"%Y/%m/%d %H:%M:%OS"
。
Any help is appreicated.任何帮助都很受欢迎。
Using the lubridate package from tidyverse, you can readily convert to your desired format.使用 tidyverse 的 lubridate package,您可以轻松转换为所需的格式。
library(lubridate)
oldformat <- as.character("10/13/2022 01:12:33")
newformat <- mdy_hms(oldformat)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.