答案 0 :(得分:1)
使用lubridate
,我们可以使用mdy_hm
转换为datetime对象,然后提取year
,month
和day
library(lubridate)
v1 <- mdy_hm(df1$Date)
df2 <- transform(df1, Year = year(v1), Month = month.abb[month(v1)], Day = day(v1))
df2
# Date Year Month Day
#1 3/30/2008 0:04 2008 Mar 30
#2 10/15/2009 10:15 2009 Oct 15
df1 <- data.frame(Date = c("3/30/2008 0:04", "10/15/2009 10:15"))