简体   繁体   English

日期时间转换——R中从非标准格式到标准明确格式

[英]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.我曾尝试使用诸如formatas.POSIXltas.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.

相关问题 R 中字符串到日期转换的“标准明确日期”格式是什么? - What are the "standard unambiguous date" formats for string-to-date conversion in R? R 中字符串到日期转换的“标准明确日期”错误 - Error with the “standard unambiguous date” for string-to-date conversion in R 字符串不是明确的标准格式 - the string is not in an unambiguous standard format 转换为日期格式错误:字符串不是标准的明确格式 - Convert to date format error: character string is not in a standard unambiguous format 尝试根据R中的日期进行过滤,并在charToDate(x)中收到错误消息:字符串不是标准的明确格式 - Trying to filter based on Date in R, receiving Error in charToDate(x) : character string is not in a standard unambiguous format 从R到格林威治的日期格式设置为R中的标准时间 - Format Date from Offset to Greenwich to standard time in R 字符串不是标准的明确格式 - character string is not in a standard unambiguous format charToDate(x) 中的 Ggplot 错误:R 中的字符串不是标准的明确格式 - Ggplot Error in charToDate(x) : character string is not in a standard unambiguous format in R 在R中修复.csv文件,以避免“字符字符串不是标准的明确格式” - Fixin .csv file in R to avoid “character string is not in a standard unambiguous format” R:charToDate(x) 中的错误:字符串不是标准的明确格式 - R: Error in charToDate(x) : character string is not in a standard unambiguous format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM