RE: Sorting text-file data into list lists
- To: mathgroup at smc.vnet.net
- Subject: [mg46267] RE: [mg46234] Sorting text-file data into list lists
- From: David.Annetts at csiro.au
- Date: Thu, 12 Feb 2004 22:46:48 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi Curt,
> 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.
Try,
In[5]:=
Import["c:/tmpfiles/test.txt", "Table"]
Out[5]=
{{col1,col2,col3,col4},{row1,1.1,
1.2,1.3,1.4},{row2,2.1,2.2,2.3,2.4},{row3,3.1,3.2,3.3,3.4},{row4,4.1,4.2,\
4.3,4.4},{row5,5.1,5.2,5.3,5.4},{row6,6.1,6.2,6.3,6.4}}
Regards,
Dave.
==========================================
Dr. David Annetts
EM Modelling Analyst
CSIRO DEM Tel: +612 9490 5416
North Ryde Fax: +612 9490 5467
Australia David.Annetts at csiro.au
===========================================