r - 日期和时间

标签 r datetime

我读了很多博客,但找不到我的问题的答案:

我有一个日期 2020-25-02 17:45:03,我想将其转换为日期和时间两列。

hello <- strptime(as.character("2020-25-02 17:42:03"),"%Y-%m-%d %H:%M:%S")
df$day <- as.Date(hello, format = "%Y-%d-%m")

但我也想要df$time。这可能吗?

最佳答案

 dtimes = c("2002-06-09 12:45:40","2003-01-29 09:30:40",
+            "2002-09-04 16:45:40","2002-11-13 20:00:40",
+            "2002-07-07 17:30:40")
> dtparts = t(as.data.frame(strsplit(dtimes,' ')))
> row.names(dtparts) = NULL
> thetimes = chron(dates=dtparts[,1],times=dtparts[,2],
+                  format=c('y-m-d','h:m:s'))
> thetimes
[1] (02-06-09 12:45:40) (03-01-29 09:30:40) (02-09-04 16:45:40)
[4] (02-11-13 20:00:40) (02-07-07 17:30:40)

请参阅此link

关于r - 日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65753318/

相关文章:

python - Pandas:根据开始和结束日期范围逐月求和

r - 从整齐的数据中提取参数子集的唯一组合

r - 从 data.tables 绘制直方图时,maxn 不是此 j 列长度的精确倍数

r - ctree()-如何获取每个终端节点的拆分条件列表?

R 仅从 power.t.test 中提取功率

php - 如何使用 **TIME ZONE** 将 NSDate 存储到 DATETIME?

regex - 使用 gsub 创建统一的时间格式

python - pandas-更改重新采样时间序列的开始和结束日期

rbind 列表并恢复名称

javascript - momentjs 查找差异并以特定格式显示