我有一个带有日期时间字符列的数据框。
当我使用 时as.Date
,我的大部分字符串都被正确解析,除了少数情况。下面的示例有望向您展示发生了什么。
# my attempt to parse the string to Date -- uses the stringr package
prods.all$Date2 <- as.Date(str_sub(prods.all$Date, 1,
str_locate(prods.all$Date, " ")[1]-1),
"%m/%d/%Y")
# grab two rows to highlight my issue
temp <- prods.all[c(1925:1926), c(1,8)]
temp
# Date Date2
# 1925 10/9/2009 0:00:00 2009-10-09
# 1926 10/15/2009 0:00:00 0200-10-15
如您所见,某些日期的年份不准确。当日期为两位数时,似乎会出现这种模式。
您可以提供的任何帮助将不胜感激。