Re: Sorting paired columns of dates and values
- To: mathgroup at smc.vnet.net
- Subject: [mg106699] Re: Sorting paired columns of dates and values
- From: Garapata <warsaw95826 at mypacks.net>
- Date: Thu, 21 Jan 2010 04:54:29 -0500 (EST)
- References: <hj6qj5$8vc$1@smc.vnet.net>
I've made a bit of progress on this with the following functions: uniqueDates[data_, year_] := Module[{step1, step2, step3},=E2=80=A8 step1 = Flatten[Rest[data][[All, Range[1, Dimensions[data][[2]], 2]]]]; step2 = Delete[step1, Position[step1, ""]];=E2=80=A8 step3 = Union[step2]; DeleteCases[step3, _?(ToExpression[StringTake[#, -4]] < year &)]]; This takes my original data as an input and returns a sorted list of unique dates. I need this (or some functional equivalent) because I discovered that each of my paired data and value columns may not have the same set of dates between any two given dates. Some may not have values for holidays or weekends others may. Also, as I described in my first post, some of the paired columns start with earlier dates than others. I also discovered in the data set that I have "" (empty strings) in some positions for both dates and data values. Next I wrote the following: cleanData[dataIn_, index_] := Module[{temp1}, temp1 = Rest[dataIn[[All, index ;; index + 1]]]; Delete[temp1, Position[temp1[[All, 1]], ""]] ]; The above, takes my original data and an index corresponding to a date column of one of the paired columns of date and values from the original data as input. It returns a matrix with just 2 columns corresponding to dates and values having delated rows without data. Note: the Rest[] just takes out a header row. Next: deleteDatesBeforeYr[data_, year_] := DeleteCases[ data, _?(ToExpression[StringTake[#[[1]], -4]] < year &)]; The above, takes input from the output of cleanData[] and deletes rows with dates prior to a specified year. These last two functions only work on one date and value paired column from the original data set at a time, so they could stand some improvement to work all at once. Still, at this point I can produce: 1. A list of sorted unique "master" dates and 2. Several matrices each with a date and data column. Now I need to combine them into a single matrix with the unique "master" dates in the first column and the data from each of the several 2 column matrices aligned in the correct row of the date column. (I know this will leave me with some blank entries at some positions in the data columns of the matrix. I need to give some thought to what to do with these later.) After these 3 posts and longwinded explanations, if anyone has stayed with this and can suggest simpler ways to do the above and a way to do the next step to get me what I need, I will very much appreciate the guidance. Thx G (Wouldn't it make things a bit easier if we could edit our posts? Just wondering)