我有一个数据框,其中一列包含数百个日期格式的日期,例如:
as.Date(c("2011-08-13","2011-09-13","2010-06-12","2012-09-13","2010-09-13","2012-05-26","2012-07-20"))
现在我只想选择 15.03 < date < 15.8 的行(所有日期在 3 月 15 日到 10 月 15 日之间,不考虑年份)。有没有一种简单的方法来选择(索引)?
我稍微修改了我接受的答案,如下:
a <- as.Date(c("2011-08-13","2011-09-13","2010-06-12","2012-09-13","2010-09-13","2012-05-26","2012-07-20"))
lower <- as.Date("03-15",format="%m-%d")
upper <- as.Date("08-15",format="%m-%d")
a[format(a,"%m-%d") < format(upper,"%m-%d") & format(a,"%m-%d") > format(lower,"%m-%d")]
[1] "2011-08-13" "2010-06-12" "2012-05-26" "2012-07-20"