gpt4 book ai didi

r - 使用保存日期的参数在 xts 中设置子集

转载 作者:行者123 更新时间:2023-12-04 17:23:51 25 4
gpt4 key购买 nike

我熟悉 xts 子集功能。但是,我找不到一种优雅的方法来对 进行子集化参数化 日期范围。像这样:

times = c(as.POSIXct("2012-11-03 09:45:00 IST"),
as.POSIXct("2012-11-05 09:45:00 IST"))

#create an xts object:
xts.obj = xts(c(1,2),order.by = times)

#filter with these dates:
start.date = as.POSIXct("2012-11-03")
end.date = as.POSIXct("2012-11-04")

#instead of xts["2012-11-03"/"2012-11-04"], do something like this:
xts[start.date:end.date]

有人有任何想法吗?谢谢!

最佳答案

您可以粘贴 start.dateend.date对象在一起,由 "::" 分隔或 "/" ,然后使用它来进行子集化。

R> xts.obj[paste(start.date,end.date,sep="::")]
[,1]
2012-11-03 09:45:00 1

关于r - 使用保存日期的参数在 xts 中设置子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14101694/

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