Re: Positions of earliest dates for each month in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg106417] Re: [mg106404] Positions of earliest dates for each month in a list
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 12 Jan 2010 04:47:21 -0500 (EST)
- References: <201001112352.SAA21004@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
If myDates is sorted: 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}}; Accumulate@Prepend[Most@Tally[myDates[[All, {1, 2}]]][[All, 2]], 1] {1, 2, 5, 8} Otherwise, sort it first. Bobby On Mon, 11 Jan 2010 17:52:55 -0600, Garapata <warsaw95826 at mypacks.net> 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. > -- DrMajorBob at yahoo.com
- References:
- Positions of earliest dates for each month in a list of dates
- From: Garapata <warsaw95826@mypacks.net>
- Positions of earliest dates for each month in a list of dates