Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Rearranging a data array containing calendrical as well as data entries.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg54839] Re: [mg54827] Rearranging a data array containing calendrical as well as data entries.
  • From: DrBob <drbob at bigfoot.com>
  • Date: Fri, 4 Mar 2005 05:07:37 -0500 (EST)
  • References: <200503030329.WAA21121@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

Here's a start:

rawData=Import["test.txt","Table"]

{{1999,1,1,489.82,489.82,495.01,495.01,495.01,495.01,495.01,490.51},{1999,1,2,
     490.51,490.51,490.51,490.51,490.38,490.38,490.38,490.38},{
   1999,1,3,490.38,510.38,510.38,510.38,510.38,510.38,528.66,528.66},{1999,1,4,
     528.66,528.66,528.66,501.68,501.68,501.68,501.68},{1999,2,
   1,501.68,496.44,496.44,496.44,496.44,496.44,478.72,478.72},{1999,2,2,478.72,
     478.72,478.72,452.82,452.82,452.82,452.82,452.82},{1999,2,
   3,450.19,450.19,450.19,450.19,450.19,443.98,443.98,443.98},{1999,2,4,443.98,
     443.98,440.14,440.14},{1999,3,1,440.14,440.14,440.14,453.64,
     453.64,453.64,453.64,453.64},{1999,3,2,503.98,503.98,503.98,503.98,503.98,
     500.84,500.84,500.84},{1999,3,3,500.84,500.84,473.48,473.48,
     473.48,473.48,473.48,463.19},{1999,3,4,463.19,463.19,463.19,463.19,457.54,
     457.54,457.54}}

Clear[dateValue, month, twoDigit]
twoDigit[i_Integer?Positive] := StringJoin @@
    PadLeft[Characters@ToString@i, 2, "0"]
month[i_Integer] /; 1 <= i <= 12 := month[i] = {"Jan", "Feb", "Mar",
  "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}[[i]]
dateValue@{yr_, mo_, wk_, values___} := Transpose@{twoDigit[# + 7(
   wk - 1)] <> month@mo <> ToString@yr & /@ Range@Length@{values}, {values}}
Flatten[dateValue /@ rawData, 1]

{{"01Jan1999", 489.82},
   {"02Jan1999", 489.82},
   {"03Jan1999", 495.01},
   {"04Jan1999", 495.01},
   {"05Jan1999", 495.01},
   {"06Jan1999", 495.01},
   {"07Jan1999", 495.01},
   {"08Jan1999", 490.51},
   {"08Jan1999", 490.51},
   {"09Jan1999", 490.51},
   {"10Jan1999", 490.51},
   {"11Jan1999", 490.51},
   {"12Jan1999", 490.38},
   {"13Jan1999", 490.38},
   {"14Jan1999", 490.38},
   {"15Jan1999", 490.38},
   {"15Jan1999", 490.38},
   {"16Jan1999", 510.38},
   {"17Jan1999", 510.38},
   {"18Jan1999", 510.38},
   {"19Jan1999", 510.38},
   {"20Jan1999", 510.38},
   {"21Jan1999", 528.66},
   {"22Jan1999", 528.66},
   {"22Jan1999", 528.66},
   {"23Jan1999", 528.66},
   {"24Jan1999", 528.66},
   {"25Jan1999", 501.68},
   {"26Jan1999", 501.68},
   {"27Jan1999", 501.68},
   {"28Jan1999", 501.68},
   {"01Feb1999", 501.68},
   {"02Feb1999", 496.44},
   {"03Feb1999", 496.44},
   {"04Feb1999", 496.44},
   {"05Feb1999", 496.44},
   {"06Feb1999", 496.44},
   {"07Feb1999", 478.72},
   {"08Feb1999", 478.72},
   {"08Feb1999", 478.72},
   {"09Feb1999", 478.72},
   {"10Feb1999", 478.72},
   {"11Feb1999", 452.82},
   {"12Feb1999", 452.82},
   {"13Feb1999", 452.82},
   {"14Feb1999", 452.82},
   {"15Feb1999", 452.82},
   {"15Feb1999", 450.19},
   {"16Feb1999", 450.19},
   {"17Feb1999", 450.19},
   {"18Feb1999", 450.19},
   {"19Feb1999", 450.19},
   {"20Feb1999", 443.98},
   {"21Feb1999", 443.98},
   {"22Feb1999", 443.98},
   {"22Feb1999", 443.98},
   {"23Feb1999", 443.98},
   {"24Feb1999", 440.14},
   {"25Feb1999", 440.14},
   {"01Mar1999", 440.14},
   {"02Mar1999", 440.14},
   {"03Mar1999", 440.14},
   {"04Mar1999", 453.64},
   {"05Mar1999", 453.64},
   {"06Mar1999", 453.64},
   {"07Mar1999", 453.64},
   {"08Mar1999", 453.64},
   {"08Mar1999", 503.98},
   {"09Mar1999", 503.98},
   {"10Mar1999", 503.98},
   {"11Mar1999", 503.98},
   {"12Mar1999", 503.98},
   {"13Mar1999", 500.84},
   {"14Mar1999", 500.84},
   {"15Mar1999", 500.84},
   {"15Mar1999", 500.84},
   {"16Mar1999", 500.84},
   {"17Mar1999", 473.48},
   {"18Mar1999", 473.48},
   {"19Mar1999", 473.48},
   {"20Mar1999", 473.48},
   {"21Mar1999", 473.48},
   {"22Mar1999", 463.19},
   {"22Mar1999", 463.19},
   {"23Mar1999", 463.19},
   {"24Mar1999", 463.19},
   {"25Mar1999", 463.19},
   {"26Mar1999", 457.54},
   {"27Mar1999", 457.54},
   {"28Mar1999", 457.54}}

Bobby


On Wed, 2 Mar 2005 22:29:16 -0500 (EST), Gilmar <gilmar.rodriguez at nwfwmd.state.fl.us> wrote:

> Dear Mathematica User Friends:
>
> I have a file containing flow data from the USGS, in the following
> format:
>
> 1999 1 1 489.82 489.82 495.01 495.01 495.01 495.01 495.01 490.51
> 1999 1 2 490.51 490.51 490.51 490.51 490.38 490.38 490.38 490.38
> 1999 1 3 490.38 510.38 510.38 510.38 510.38 510.38 528.66 528.66
> 1999 1 4 528.66 528.66 528.66 501.68 501.68 501.68 501.68
> 1999 2 1 501.68 496.44 496.44 496.44 496.44 496.44 478.72 478.72
> 1999 2 2 478.72 478.72 478.72 452.82 452.82 452.82 452.82 452.82
> 1999 2 3 450.19 450.19 450.19 450.19 450.19 443.98 443.98 443.98
> 1999 2 4 443.98 443.98 440.14 440.14
> 1999 3 1 440.14 440.14 440.14 453.64 453.64 453.64 453.64 453.64
> 1999 3 2 503.98 503.98 503.98 503.98 503.98 500.84 500.84 500.84
> 1999 3 3 500.84 500.84 473.48 473.48 473.48 473.48 473.48 463.19
> 1999 3 4 463.19 463.19 463.19 463.19 457.54 457.54 457.54
>
> This format is used by the USGS to compress their data records.
>
> Each row contains:
> Year, Month Number(1 to 12), Row Number (1 to 4), and data entries.
>
> The first row:
> 1999 1 1 489.82 489.82 495.01 495.01 495.01 495.01 495.01 490.51
> contains flow values corresponding to: January 1 to January 8,
> of the year 1999.
>
> The second row:
> 1999 1 2 490.51 490.51 490.51 490.51 490.38 490.38 490.38 490.38
> contains flow values corresponding to: January 9 to January 16,
> of the year 1999.
>
> The third row:
> 1999 1 3 490.38 510.38 510.38 510.38 510.38 510.38 528.66 528.66
> contains flow values corresponding to: January 17 to January 24,
> of the year 1999.
>
> The fourth row:
> 1999 1 4 528.66 528.66 528.66 501.68 501.68 501.68 501.68
> contains flow values corresponding to: January 25 to January 31,
> of the year 1999.
>
> I think that you get the picture of how this data set is assembled.
>
> What I need is a program that can turn the above mentioned horizontal
> array, into a simple vertical array, containing two columns;
> the first column contains the dates when the data was collected,
> and the second column contains the flow values; i.e.
>
> 01Jan1999 489.82
> 02Jan1999 489.82
> 03Jan1999 495.01
> etc.
>
> If I give the program a starting date, and ending date for an
> arbitrary record; the program should be able to allocate two
> arrays to:
>
> (1.) put the dates between the starting date, and ending date,
> to form the first column of the vertical array.
>
> (2.)match correctly those dates with the data to appear in
> the second column of the vertical array.
>
> The program should discern between regular years, and leap
> years.  Those of you that are still using FORTRAN, and have
> experienced how difficult it is to deal with date functions
> using FORTRAN, might sympathize with my request.
>
> P.S. To get a larger set of USGS flow data to test your program
> please download the following file:
>
> http://www.gilmarlily.netfirms.com/download/flow.dat
>
> Thank you for your help!
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Rearranging a data array containing calendrical as well as data entries.
  • Next by Date: Re: Rearranging a data array containing calendrical as well as data entries.
  • Previous by thread: Re: Rearranging a data array containing calendrical as well as data entries.
  • Next by thread: Re: Rearranging a data array containing calendrical as well as data entries.