Re: Help with DateListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg82221] Re: Help with DateListPlot
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 15 Oct 2007 01:26:09 -0400 (EDT)
- References: <fesq3k$p4n$1@smc.vnet.net>
KTugbawa at gmail.com schrieb: > How do you use the DateList Plot function when you have a 3-vector > database. The first column is the date, the second column contains the > names, and the last column contains the returns. I know that you have > to use a loop. I know I have not to use a loop ;-) The data looks like this: > > Date Item return > 1/2/01 TBill 0.67 > 1/3/01 SP 0.78 > 1/4/01 inv 0.5 > 1/5/01 inve 0.6 > .. > .. > .. > .. > 1/12/01 Forc 1.2 > 1/2/02 TBill 0.4 > 1/3/02 SP 0.2 > 1/4/02 inv 0.6 > 1/5/02 inve 0.9 > .. > .. > .. > .. > 1/12/02 Forc 1.6 > > This patterns continues until 1/6/2007 > > I need to use DataListPlot to plot the returns of each item. > > Let`s see how the file is read in: In[1]:= tbl = Import["thefile.txt", "Table"]; have a look at the first line FullForm[tbl[[1]]] Out[2]//FullForm= {"1/2/01", "TBill", 0.67} We have to convert the string "mm/dd/yy" to a list {y,m,d}. Additionally I add 2000 to the year: In[3]:= data = Apply[{ToExpression[StringJoin["{", StringReplace[#1, "/" -> ","], "}"]][[{3, 1, 2}]] + {2000, 0, 0}, #3} & , tbl, {1}] Out[3]= {{{2001, 1, 2}, 0.67}, {{2001, 1, 3}, 0.78}, {{2001, 1, 4}, 0.5}, {{2001, 1, 5}, 0.6}} I do not have access to Mathematica 6 but according to http://reference.wolfram.com/mathematica/ref/DateListPlot.html , DateListPlot[data] should work. Regards, Peter
- Follow-Ups:
- Re: Re: Help with DateListPlot
- From: Darren Glosemeyer <darreng@wolfram.com>
- Re: Re: Help with DateListPlot