我有一个 data.frame 如下:
Dat1 <- data.frame(dateTime = as.POSIXct(c("2012-05-03 00:00","2012-05-03 02:00",
"2012-05-03 02:30","2012-05-03 05:00",
"2012-05-03 07:00","2012-05-04 07:00"),
tz = 'UTC'),x1 = rnorm(6))
给予:
> Dat1
dateTime x1
1 2012-05-03 00:00:00 -0.3529501
2 2012-05-03 02:00:00 1.9086742
3 2012-05-03 02:30:00 -0.4707939
4 2012-05-03 05:00:00 -1.7001035
5 2012-05-03 07:00:00 -1.3389383
6 2012-05-04 07:00:00 0.6985237
我想将此 data.frame 减少为仅包含给定日期超过 n 点的行。所以,如果我说 n = 2,Dat1 应该减少到:
> Dat1
dateTime x1
1 2012-05-03 00:00:00 -0.3529501
2 2012-05-03 02:00:00 1.9086742
3 2012-05-03 02:30:00 -0.4707939
4 2012-05-03 05:00:00 -1.7001035
5 2012-05-03 07:00:00 -1.3389383
我希望这对任意数量的列的 data.frame 有用,而不仅仅是对于这个例子。