MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Positions of earliest dates for each month in a list of dates

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106429] Re: Positions of earliest dates for each month in a list of dates
  • From: dh <dh at metrohm.com>
  • Date: Tue, 12 Jan 2010 04:49:39 -0500 (EST)
  • References: <higdki$kg9$1@smc.vnet.net>


Hi,

one way of doing this (assuming the data are in chronological order, 

otherwise sort them first):

1) Split the data according to year and month.

2) Take first entry of every sublist

here is the code:

First /@ Split[myDates, Equal[Take[#1, 2], Take[#2, 2]] &]

Daniel



Garapata wrote:

> I have a list of 20+ years of dates (from earliest to latest) in

> DateList format:

> 

> A subset of the list should suffice to illustrate:

> 

> myDates = {{1984,12,7,0,0,0}, {1985,1,3,0,0,0},{1985,1,4,0,0,0},

> {1985,1,7,0,0,0}

> ,{1985,2,1,0,0,0},{1985,2,4,0,0,0},{1985,2,5,0,0,0},{1985,3,4,0,0,0},

> {1985,3,5,0,0,0},

> {1985,3,6,0,0,0},...};

> 

> The list does not include all dates, weekends and it may not include

> some holidays or other seemingly arbitrary days.

> 

> I need to find out the positions of the the first date appearing in

> each month.

> 

> So, from the sample of myDates above I need to get:

> 

> {1, 2, 5, 8}

> 

> Corresponding to the positions for the dates:

> 

> {{1984,12,7,0,0,0},

> {1985,1,3,0,0,0},

> {1985,2,1,0,0,0},

> {1985,3,4,0,0,0}}

> 

> I've tried working with Position, Split, SplitBy, Ordering, Sort, and

> Sortby, but haven't made much progress.

> 

> I've also tried creating an index for the dates like this:

> 

> SplitBy[Transpose[Join[{myDates}, {Range[1, Length[myDates]]}]]];

> 

> and hoped to use its output to sort or split the list into sublists of

> each month then just use Part to take the first date in each month

> with its paired index, but I still can't figure out how to do it.

> 

> I've got the feeling I've missed a simple solution to this, any help

> much appreciated.

> 




  • Prev by Date: Re: More /.{I->-1} craziness
  • Next by Date: Re: Re: Radicals simplify
  • Previous by thread: Re: Positions of earliest dates for each month in a list of dates
  • Next by thread: Re: Positions of earliest dates for each month in a list of dates