On Thu, Apr 8, 2010 at 11:42 AM, Sergey Goriatchev <serg...@gmail.com> wrote: > Thank you, Gabor! This is a very elegant solution. > But instead of general last day of month in the index, how can I have > last day of each month as they are presented in "a", for example, not > March 31, but March 27? >
Try this: > a[!duplicated(as.yearmon(time(a)), fromLast = TRUE)] 2009-03-27 2009-04-30 2009-05-29 2009-06-26 2 5 8 9 or this: > last.date <- ave(time(a), as.yearmon(time(a)), FUN = function(x) tail(x, 1)) > aggregate(a, last.date, tail, 1) 2009-03-27 2009-04-30 2009-05-29 2009-06-26 2 5 8 9 Note that the examples in ?aggregate.zoo include some that are very similar examples are shown here. Also see ?ave . ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.