Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*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 1999

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

Search the Archive

Re: ReadList

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18855] Re: [mg18787] ReadList
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Thu, 22 Jul 1999 22:57:50 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

James l. Fisher [jlfisher at imt.net] wrote:

> I want to read the following data which is in ascii form into a list
>
> 09/22/98 12:15 2.36
> 09/22/98 12:30 2.37
> 09/22/98 12:45 2.38
> etc
>
>  How can I use ReadList, or some other command, to enter this
> into the form
>
>  {{09/22/98,12:15,2.36},{09/22/98,12:30,2.37},{09/22/98,12:45, 2.38}}
>
> How could I read each column into a seperate list also.

James,

I assume your data are, e.g., in an Excel table. First, save them as
tab-delimited text in a file origdata.txt, say. Then you can read them in
with

In[1]:=
data = ReadList["origdata.txt", Word, RecordLists -> True]
Out[1]=
{{"09/22/98", "12:15", "2.36"}, {"09/22/98", "12:30", "2.37"}, {"09/22/98",
    "12:45", "2.38"}}

You can place each column in a separate list with

In[2]:=
fil1 = Transpose[data][[1]]
Out[2]=
{"09/22/98", "09/22/98", "09/22/98"}
In[3]:=
fil2 = Transpose[data][[2]]
Out[3]=
{"12:15", "12:30", "12:45"}
In[4]:=
fil3 = Transpose[data][[3]]
Out[4]=
{"2.36", "2.37", "2.38"}

The thing is, all the values in data are strings. If you want to do
something useful with them, they have to be converted to numbers. But in
their present form only the third column can be converted directly:

In[5]:=
newdata = data /. {x1_, x2_, x3_String} :> {x1, x2, ToExpression[x3]}
Out[5]=
{{"09/22/98", "12:15", 2.36}, {"09/22/98", "12:30", 2.37}, {"09/22/98",
    "12:45", 2.38}}

If you want to use the first two columns, e.g. for plotting or regression
analysis, you must express their elements in numerical form. You may take an
arbitrary origin for date, so that each date is referred to it, and the same
for the time of day. So, e.g., let 09/20/98 be the origin for date, and 0:00
the origin for time of day. Your data can then be prepared in Excel, which
has a good menu for time and date functions, or you can use functions Date
and FromDate in Mathematica. The idea is that all your date and time values
be expressed as numbers.





  • Prev by Date: Re: Dialog boxes
  • Next by Date: Slow Mathematica front end
  • Previous by thread: RE: ReadList
  • Next by thread: Re: ReadList