I wondered if anyone has another or even a more direct way of finding the last dates of each month available from a list of successive dates?
I currently do the following (note: nothing special about WeatherData[]
here, I just used it to generate a list of dates):
WeatherData["KMDZ", "MeanTemperature", {{2007, 1, 1}, {2007, 12, 31}, "Day"}][[All, 1]];
Last[#] & /@ SplitBy[%, DateList[#][[2]] &]
{{2007, 1, 31}, {2007, 2, 28}, {2007, 3, 31}, {2007, 4, 30}, {2007, 5, 31}, {2007, 6, 30}, {2007, 7, 31}, {2007, 8, 31}, {2007, 9,30}, {2007, 10, 31}, {2007, 11, 30}, {2007, 12, 31}}
This works fine. I just wondered if I could think about this problem in a different way.
It seems the question needs a clarification. The starting list of dates may not include every date in a given month as such; it also may not include the actual last date of any given month. I need to find the last date in any month available in the list.
Last /@ (* stuff *)
instead ofLast[#] & /@ (* stuff *)
... otherwise, your method looks perfectly straightforward. $\endgroup$GatherBy[wd[[All, 1]], #[[2]] &][[All, -1]]
==Last /@ SplitBy[wd[[All, 1]], DateList[#][[2]] &]
$\endgroup$