在R中选择window的时间段;格式 "dd/mm/yyyy h:m:s" (Windows 7)
Selecting a time period with window in R; format "dd/mm/yyyy h:m:s" (Windows 7)
我有以下问题。我想使用以下代码 select 每日数据的特定时间段,例如这个:
window(Modellwind.zoo, start = as.Date("01/Jan/2001 12:00:00"), end = as.Date("4/Jan/2001 12:00:00"))
我收到以下错误消息:charToDate(x) 出错:
字符串不是标准的明确格式
当我试图用函数 anydate 找到可接受的时间格式时,它也没有工作:
library(anytime)
anydate("01/Jan/2001 12:00:00")
使用以下代码:
window(Modellwind.zoo, start = as.Date("2001-01-01"), end = as.Date("2001-01-04"))
不幸的是,我收到以下错误:
**Warning messages:
1: In which(in.index & all.indexes >= start & all.indexes <= end) :
Incompatible methods ("Ops.dates", "Ops.Date") for ">="
2: In which(in.index & all.indexes >= start & all.indexes <= end) :
Incompatible methods ("Ops.dates", "Ops.Date") for "<="**
以下代码包含 Modellwind.zoo 的示例。
structure(c(9.08093655399134, 6.51590181162631, 7.14637946155745,
1.43900253813098, 6.78880326680026, 14.3182887821646, 16.3360242476697,
16.1781018622214, 17.2200845065928, 15.6439142273171, 8.10504553259712,
3.78898221928137, 6.78608582121557, 7.18116948778303, 5.0299974451978,
3.49148782050232, 6.9941692218925, 8.45512766287497, 12.0693672354131,
11.987955907515, 10.3290912344961, 13.4506307038479, 21.7989491163794,
14.0085737502259, 14.5883127217965, 11.8048508250059, 24.7915690531695,
19.151192329502, 12.1739793389357, 11.9410486288817, 20.9967608089789,
15.2111025271479, 5.90129944159158, 2.42733488656831, 7.20743282263504,
22.737089035552, 14.8219437253637, 14.0558804343021, 8.98137356225915,
12.9592918632241, 18.4870237580719, 9.11790624009415, 2.27721679625411,
2.61125956054424, 3.26998407545227, 5.35392572192135, 4.95193258824599,
6.86224460928498, 9.06594694653957, 12.4505570716657, 12.740653858499,
15.8771799446521, 12.5618618366812, 3.58848453998801, 10.9966305297934,
4.86674413518877, 10.7031531327265, 16.2043681264107, 12.0587344974091,
2.10949588086561), index = structure(c(18659.5, 18660.5, 18661.5,
18662.5, 18663.5, 18664.5, 18665.5, 18666.5, 18667.5, 18668.5,
18669.5, 18670.5, 18671.5, 18672.5, 18673.5, 18674.5, 18675.5,
18676.5, 18677.5, 18678.5, 18679.5, 18680.5, 18681.5, 18682.5,
18683.5, 18684.5, 18685.5, 18686.5, 18687.5, 18688.5, 18689.5,
18690.5, 18691.5, 18692.5, 18693.5, 18694.5, 18695.5, 18696.5,
18697.5, 18698.5, 18699.5, 18700.5, 18701.5, 18702.5, 18703.5,
18704.5, 18705.5, 18706.5, 18707.5, 18708.5, 18709.5, 18710.5,
18711.5, 18712.5, 18713.5, 18714.5, 18715.5, 18716.5, 18717.5,
18718.5), .Dim = 60L, format = structure(c("dd/mm/yyyy", "h:m:s"
), .Names = c("dates", "times")), origin = c(12L, 1L, 1949L), class = c("chron",
"dates", "times")), class = "zoo")
Modellwind.zoo
的索引是chron
。这就是为什么您尝试通过 Date
进行子集化的尝试没有成功(您的第一次尝试失败是因为 as.Date
需要 %Y-%m-%d
格式)。在按 Date
:
子集之前将索引更改为 Date
Modellwind.zoo.Date <- Modellwind.zoo
index(Modellwind.zoo.Date) <- as.Date(index(Modellwind.zoo.Date))
window(Modellwind.zoo.Date, start = as.Date("2001-01-01"), end = as.Date("2001-01-04"))
# 2001-01-01 2001-01-02 2001-01-03 2001-01-04
# 9.080937 6.515902 7.146379 1.43900
或者将索引保留为 chron
并通过 chron
个对象进行子集化。请注意,Modellwind.zoo
中 chron
索引的来源是 1949-12-01,而不是 1990-01-01 的默认时间来源,因此您需要指定它以避免关于 mis-matched 起源.
beg.chron <- as.chron("01/01/2001", origin = c(12, 1, 1949))
end.chron <- as.chron("01/04/2001", origin = c(12, 1, 1949))
window(Modellwind.zoo, start = beg.chron, end = end.chron)
# (01/Jan/2001 12:00:00) (02/Jan/2001 12:00:00) (03/Jan/2001 12:00:00)
# 9.080937 6.515902 7.146379
我有以下问题。我想使用以下代码 select 每日数据的特定时间段,例如这个:
window(Modellwind.zoo, start = as.Date("01/Jan/2001 12:00:00"), end = as.Date("4/Jan/2001 12:00:00"))
我收到以下错误消息:charToDate(x) 出错: 字符串不是标准的明确格式
当我试图用函数 anydate 找到可接受的时间格式时,它也没有工作:
library(anytime)
anydate("01/Jan/2001 12:00:00")
使用以下代码:
window(Modellwind.zoo, start = as.Date("2001-01-01"), end = as.Date("2001-01-04"))
不幸的是,我收到以下错误:
**Warning messages:
1: In which(in.index & all.indexes >= start & all.indexes <= end) :
Incompatible methods ("Ops.dates", "Ops.Date") for ">="
2: In which(in.index & all.indexes >= start & all.indexes <= end) :
Incompatible methods ("Ops.dates", "Ops.Date") for "<="**
以下代码包含 Modellwind.zoo 的示例。
structure(c(9.08093655399134, 6.51590181162631, 7.14637946155745,
1.43900253813098, 6.78880326680026, 14.3182887821646, 16.3360242476697,
16.1781018622214, 17.2200845065928, 15.6439142273171, 8.10504553259712,
3.78898221928137, 6.78608582121557, 7.18116948778303, 5.0299974451978,
3.49148782050232, 6.9941692218925, 8.45512766287497, 12.0693672354131,
11.987955907515, 10.3290912344961, 13.4506307038479, 21.7989491163794,
14.0085737502259, 14.5883127217965, 11.8048508250059, 24.7915690531695,
19.151192329502, 12.1739793389357, 11.9410486288817, 20.9967608089789,
15.2111025271479, 5.90129944159158, 2.42733488656831, 7.20743282263504,
22.737089035552, 14.8219437253637, 14.0558804343021, 8.98137356225915,
12.9592918632241, 18.4870237580719, 9.11790624009415, 2.27721679625411,
2.61125956054424, 3.26998407545227, 5.35392572192135, 4.95193258824599,
6.86224460928498, 9.06594694653957, 12.4505570716657, 12.740653858499,
15.8771799446521, 12.5618618366812, 3.58848453998801, 10.9966305297934,
4.86674413518877, 10.7031531327265, 16.2043681264107, 12.0587344974091,
2.10949588086561), index = structure(c(18659.5, 18660.5, 18661.5,
18662.5, 18663.5, 18664.5, 18665.5, 18666.5, 18667.5, 18668.5,
18669.5, 18670.5, 18671.5, 18672.5, 18673.5, 18674.5, 18675.5,
18676.5, 18677.5, 18678.5, 18679.5, 18680.5, 18681.5, 18682.5,
18683.5, 18684.5, 18685.5, 18686.5, 18687.5, 18688.5, 18689.5,
18690.5, 18691.5, 18692.5, 18693.5, 18694.5, 18695.5, 18696.5,
18697.5, 18698.5, 18699.5, 18700.5, 18701.5, 18702.5, 18703.5,
18704.5, 18705.5, 18706.5, 18707.5, 18708.5, 18709.5, 18710.5,
18711.5, 18712.5, 18713.5, 18714.5, 18715.5, 18716.5, 18717.5,
18718.5), .Dim = 60L, format = structure(c("dd/mm/yyyy", "h:m:s"
), .Names = c("dates", "times")), origin = c(12L, 1L, 1949L), class = c("chron",
"dates", "times")), class = "zoo")
Modellwind.zoo
的索引是chron
。这就是为什么您尝试通过 Date
进行子集化的尝试没有成功(您的第一次尝试失败是因为 as.Date
需要 %Y-%m-%d
格式)。在按 Date
:
Date
Modellwind.zoo.Date <- Modellwind.zoo
index(Modellwind.zoo.Date) <- as.Date(index(Modellwind.zoo.Date))
window(Modellwind.zoo.Date, start = as.Date("2001-01-01"), end = as.Date("2001-01-04"))
# 2001-01-01 2001-01-02 2001-01-03 2001-01-04
# 9.080937 6.515902 7.146379 1.43900
或者将索引保留为 chron
并通过 chron
个对象进行子集化。请注意,Modellwind.zoo
中 chron
索引的来源是 1949-12-01,而不是 1990-01-01 的默认时间来源,因此您需要指定它以避免关于 mis-matched 起源.
beg.chron <- as.chron("01/01/2001", origin = c(12, 1, 1949))
end.chron <- as.chron("01/04/2001", origin = c(12, 1, 1949))
window(Modellwind.zoo, start = beg.chron, end = end.chron)
# (01/Jan/2001 12:00:00) (02/Jan/2001 12:00:00) (03/Jan/2001 12:00:00)
# 9.080937 6.515902 7.146379