gpt4 book ai didi

R - 从数据框中的特定日期或时间段提取数据

转载 作者:行者123 更新时间:2023-12-05 09:22:22 25 4
gpt4 key购买 nike

我是 R 的新手,我有一个这样的数据框:

     EndDate EndId EndTime
1 02/01/2013 251 13:32
2 03/01/2013 251 17:19
3 04/01/2013 251 16:26
4 04/01/2013 368 08:36
5 05/01/2013 386 16:58
6 01/01/2013 329 11:51

如何选择位于 03/01/2013 和 05/01/2013 之间的数据框行? (或特定时间段?)谢谢

最佳答案

我倾向于将其转换为 xts(可扩展时间序列)对象并对其使用时间序列索引。

library(xts)
df.xts <-xts(df["EndId"],order.by=as.POSIXct(paste(df$EndDate,df$EndTime),format="%m/%d/%Y %H:%M"))

df.xts["2013-03-01::2013-05-01"]
# EndId
# 2013-03-01 17:19:00 251
# 2013-04-01 08:36:00 368
# 2013-04-01 16:26:00 251
# 2013-05-01 16:58:00 386

关于R - 从数据框中的特定日期或时间段提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27206074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com