Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*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 2004

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

Search the Archive

Sorting text-file data into list lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg46234] Sorting text-file data into list lists
  • From: "Curt Fischer" <crf3 at po.cwru.edu>
  • Date: Thu, 12 Feb 2004 07:15:59 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Group:

I have a large file with lots of numeric data, in matrix form.  The rows and
the columns both have non-numeric text headers.  The comma is the delimiter.
The character at the end of lines shows up as a "paragraph" mark in MS Word;
I'm assuming it's a carriage return.

I want to import the data into a nested list, like a matrix is usually
represented in Mathematica.  But my attempts using ReadList[] have so far
failed.

In[1]:=
!!practice.txt

                  col1 ,         col2,
row1  ,      1.00  ,,        2.00,
row2   ,      3.00   ,       -4.00

In[25]:=
prac=ReadList["practice.txt", Record,
RecordSeparators\[Rule]{",","\n"},RecordLists\[Rule]True]

Out[25]=
{{                  col1 },{         col2},{row1  },{
       1.00  },{        2.00},{row2   },{      3.00   },{       -4.00}}

In[27]:=
ToExpression[prac]

Out[27]=
{{col1},{col2},{row1},{1.},{2.},{row2},{3.},{-4.}}

What I'd like is something like {{col1, col2},{row1, 1., 2.},{row2, 3., 4.}}

What am I doing wrong?  Thanks for any insights.

--
Curt Fischer


  • Prev by Date: Re: queation exporting quaternions from mathematica 5
  • Next by Date: Re: extracting a list to a list, help please
  • Previous by thread: Re: NMinimize/FindMinimum and function involving NDSolve
  • Next by thread: Re: Sorting text-file data into list lists