本文介绍了在一系列日期中查找月份的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一系列这样的日期
ds <- seq(as.Date("2011-02-01"), length=100, by="day")我想找到每月最后几天的索引
I want to find the indices of the last days of each month
我可以这样做
last_day <- seq(as.Date("2011-02-01"), length=10, by="1 month") - 1 which(ds %in% last_day)我的问题是我的日期顺序不完整,缺少某些日期,有时可能是最后一天.
my problem is that my sequence of dates is not complete, some dates are missing and sometimes this can be the last day.
例如,我删除了2月的最后一天
For example, I removed the last day of February
ds[ds == as.Date('2011-02-28')] <- NA新的最后一天现在应该是"2011-02-27".
The new last day should now be '2011-02-27'.
如何根据向量中的日期找到每个月的最后一个? 日期跨越数年.
How can I find the last of for each month based on the dates in my vector? The dates span over several years.
推荐答案尝试:
which(ave(as.numeric(ds),format(ds,"%Y%m"),FUN=function(x) x==max(x))==1)更多推荐
在一系列日期中查找月份的最后一天
发布评论