我正在将文件中的时间序列数据读入R数据帧。请参阅下面的日期列。我只是在2009年展示,因为我在这里遇到了一个我在下面描述的问题。直到这里看起来很平常。
数据:
> dput(droplevels(data[5445:5464,] ))
structure(list(V1 = structure(1:20, .Label = c("2009-03-16",
"2009-03-17", "2009-03-18", "2009-03-19", "2009-03-20", "2009-03-21",
"2009-03-22", "2009-03-23", "2009-03-24", "2009-03-25", "2009-03-26",
"2009-03-27", "2009-03-28", "2009-03-29", "2009-03-30", "2009-03-31",
"2009-04-01", "2009-04-02", "2009-04-03", "2009-04-04"), class = "factor"),
V2 = c(36.66, 29.022, 11.922, 30.048, 42.222, 37.173, -888,
29.798, 4.148, 20.86, 14.248, 3.372, 31.347, 9.335, 13.997,
28.76, 14.248, 15.81, 59.71, 29.022), V3 = c(1L, 1L, 1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), V4 = c(36.01, 43.01, 11.66, 40.16, 39.635, 29.535,
30.572, -888, 20.472, 21.635, 19.298, 0.648, 37.048, 10.11,
17.097, 29.272, 18.272, 24.222, 46.885, 45.21), V5 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), V6 = c(17.235, 32.26, 10.885, 45.46, 38.86,
23.323, 29.41, 43.397, -888, 46.885, 28.623, 15.81, 16.322,
15.285, 5.71, 21.76, 15.16, 28.372, 45.335, 59.06), V7 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), V8 = c(19.56, 33.423, 16.322, 5.96, 33.423,
22.798, 41.447, 36.01, 11.535, -888, 25.91, 24.36, 17.36,
0.26, 3.885, 25.385, 13.473, 37.56, 51.685, 29.798), V9 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), V10 = c(22.798, 47.922, -0.515, 17.097,
34.197, 26.173, 39.51, 40.673, 18.135, 18.66, -888, 15.81,
16.972, -0.252, 14.123, 23.835, 16.06, 36.785, 42.485, 43.135
), V11 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), V12 = c(16.06, 34.46, 0.785,
18.66, 33.423, 24.748, 44.56, 39.123, 18.522, 24.36, 40.41,
-888, 16.585, 13.735, 19.947, 29.41, 7.523, 41.447, 49.097,
74.997), V13 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), V14 = c(2.722, 21.897,
5.185, 26.685, 28.76, 26.947, 13.735, 37.56, 7.26, 18.135,
34.46, 15.16, -888, 11.148, 8.035, 38.86, 17.235, 48.31,
49.997, 70.985), V15 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), V16 = c(15.672,
38.86, -0.252, 51.81, 37.823, 42.623, 15.81, 34.847, 17.36,
19.698, 26.685, 17.097, 43.785, -888, 8.81, -888, 71.623,
17.097, 1.56, 43.91), V17 = c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L), V18 = c(14.123,
-888, 8.547, 44.298, -888, 24.61, -1.29, 27.46, 15.16, 19.698,
27.46, 20.21, 38.085, 11.66, -888, -888, 45.072, 15.81, 27.46,
45.46), V19 = c(1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L), V20 = c(28.372, 4.673,
7.26, 34.197, -888, -888, 6.873, 43.397, 13.085, 13.21, 33.285,
22.798, 52.072, 16.197, 9.073, -888, 56.998, 6.61, 40.797,
79.397), V21 = c(1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L), V22 = c(8.297, 27.597,
2.86, 26.173, -5.952, 48.448, 18.91, 32.647, 29.41, 20.985,
18.522, 26.173, 15.547, 11.66, 22.673, 21.123, -888, 23.572,
51.81, 63.985), V23 = c(1L, 1L, 1L, 1L, -10L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L), V24 = c(-8.802,
12.31, -7.253, -3.628, -0.777, 31.347, 15.81, 27.46, 27.46,
22.022, 21.635, 29.022, 4.922, 9.073, 19.947, 17.36, 14.385,
-888, 49.997, 28.372), V25 = c(-10L, 1L, -10L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L),
V26 = c(19.698, 24.998, -1.29, 18.135, -1.803, 64.247, 14.898,
30.185, 14.898, 8.035, 35.235, 32.385, 4.41, 15.81, 9.073,
19.698, 8.81, 40.548, -888, 69.423), V27 = c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
0L, 1L), V28 = c(16.847, -888, 4.148, 10.11, 0.01, 50.772,
27.847, 19.298, 20.472, 18.135, 26.685, 33.16, 9.073, 9.585,
11.922, 36.923, 3.497, 34.197, 81.085, -888), V29 = c(1L,
0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 0L), V30 = c(17.485, -888, -1.553, 14.248, 6.485,
45.21, 29.022, 52.335, 23.572, 11.922, 31.347, 33.685, 5.447,
17.36, 26.423, 35.11, 8.81, 34.46, 96.623, 107.635), V31 = c(1L,
0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), V32 = c(19.56, -888, 36.785, 15.81, 15.285,
63.985, 33.685, 28.623, 29.41, 9.585, 21.635, 20.21, 13.997,
17.623, 27.722, -888, 14.51, 36.785, 81.085, 74.085), V33 = c(1L,
0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 1L), V34 = c(42.222, 8.685, 33.423, 23.06, 24.097,
67.097, 25.522, -1.678, 30.572, 12.697, 8.035, 42.485, 22.798,
10.373, 19.435, -888, 16.585, 23.572, 95.722, 77.198), V35 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 1L), V36 = c(49.735, 1.685, 26.947, 23.572, 34.71,
67.097, 17.36, 11.535, 30.572, 20.86, 32.51, 37.56, 4.148,
23.323, 21.76, -888, 13.347, 27.335, 76.422, 75.647), V37 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 1L), V38 = c(53.11, 29.022, 39.123, 40.673, 28.235,
74.347, 5.31, 13.86, 47.672, 23.572, 37.173, 23.835, 13.735,
18.135, 18.66, -888, 23.448, 42.222, 84.322, 97.397), V39 = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L,
1L, 1L, 1L, 1L), V40 = c(-888, 25.135, 45.21, 35.235, 29.535,
58.16, 24.748, 19.698, 39.123, 24.873, 44.685, 23.185, -7.502,
22.022, 36.272, -888, 29.798, 43.647, 100.51, 79.535), V41 = c(0L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, -10L, 1L, 1L,
0L, 1L, 1L, 1L, 1L), V42 = c(68.647, -888, 28.235, 29.022,
27.722, 60.36, 41.835, 24.36, 16.197, 28.235, 18.135, 18.135,
4.922, 23.572, 44.435, 30.697, 13.86, 56.085, 74.085, 68.647
), V43 = c(1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), V44 = c(61.01, 25.135, -888,
22.022, 29.022, 51.298, 19.298, 20.085, 32.51, 15.035, 24.36,
24.097, 4.673, 13.735, 29.022, 0.398, 18.91, 62.435, 47.535,
62.173), V45 = c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), V46 = c(44.298,
16.06, 38.86, -888, 26.685, 49.997, 30.572, 20.085, 26.298,
35.235, 19.298, 22.022, 4.922, 15.285, 14.51, 2.46, 19.698,
80.948, 21.123, 65.535), V47 = c(1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
V48 = c(31.61, 7.26, 38.085, 34.46, -888, 54.66, 26.298,
30.185, 25.135, 18.135, 25.522, 21.51, 1.822, 6.998, 35.747,
10.235, 16.06, 58.423, 27.46, 15.81), V49 = c(1L, 1L, 1L,
1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6",
"V7", "V8", "V9", "V10", "V11", "V12", "V13", "V14", "V15", "V16",
"V17", "V18", "V19", "V20", "V21", "V22", "V23", "V24", "V25",
"V26", "V27", "V28", "V29", "V30", "V31", "V32", "V33", "V34",
"V35", "V36", "V37", "V38", "V39", "V40", "V41", "V42", "V43",
"V44", "V45", "V46", "V47", "V48", "V49"), row.names = 5445:5464, class = "data.frame")
View(data[[1]][5400:5500])
此外我转换为POSXIlt对象,然后尝试使用以下命令添加小时:
POSIX= as.POSIXlt(data[[1]])
t = rep(POSIX, each=24)+(0:23)*3600
正如我在下图中突出显示的'2009-03-30'小时00:00:00重复两次。其他日期并非如此。只有极少数日期我看到这样的重复。您可以找到任何理由或需要更多信息,请告知我们。
答案 0 :(得分:1)
问题出现在2009-03-29
,因为这是一个时间有变化的星期日(夏令时)所以凌晨2点实际上是凌晨3点。正如您在此处看到的那样,凌晨1点到凌晨3点之间存在差距,因此最后一个元素是00:00:00
而不是23:00:00
rep(POSIX[14],24)+(0:23)*3600
[1] "2009-03-29 00:00:00 CET" "2009-03-29 01:00:00 CET" "2009-03-29 03:00:00 CEST" "2009-03-29 04:00:00 CEST"
[21] "2009-03-29 21:00:00 CEST" "2009-03-29 22:00:00 CEST" "2009-03-29 23:00:00 CEST" "2009-03-30 00:00:00 CEST"
我猜测问题会随着时间的变化而出现在其他日期。
您可以使用DaylightSavingTime
包中的timeDate
函数:
使用您的日期来自的城市的名称,它将返回夏令时的日期,因此您有一个所有问题日期的列表:
head(NewYork())
New_York offSet isdst TimeZone numeric
1 1901-12-14 20:45:52 -18000 0 EST -2147397248
2 1918-03-31 07:00:00 -14400 1 EDT -1633280400
3 1918-10-27 06:00:00 -18000 0 EST -1615140000
4 1919-03-30 07:00:00 -14400 1 EDT -1601830800
5 1919-10-26 06:00:00 -18000 0 EST -1583690400
6 1920-03-28 07:00:00 -14400 1 EDT -1570381200