Re: help! to input data...
- To: mathgroup at smc.vnet.net
- Subject: [mg4243] Re: help! to input data...
- From: Paul Abbott <paul at earwax.pd.uwa.edu.au>
- Date: Sun, 23 Jun 1996 03:06:28 -0400
- Organization: University of Western Australia
- Sender: owner-wri-mathgroup at wolfram.com
Ian Collier wrote:
> Mathematica's ReadList command does not have any built-in options to
> read comma-separated data.
Really?
In[1]:= !!comma.dat
1,10,1000
2,20,2000
3,30,3000
4,40,4000
5,50,5000
6,60,6000
7,70,7000
8,80,8000
9,90,9000
10,100,10000
Surely this does what you want:
In[2]:= ReadList["comma.dat", Number, RecordSeparators->","]
Out[2]= {1, 10, 1000, 2, 20, 2000, 3, 30, 3000, 4, 40, 4000, 5, 50,
5000, 6, 60, 6000, 7, 70, 7000, 8, 80, 8000, 9, 90, 9000,
10, 100, 10000}
You can partition this, if you want:
In[3]:= Partition[%,3]
Out[3]= {{1, 10, 1000}, {2, 20, 2000}, {3, 30, 3000}, {4, 40, 4000},
{5, 50, 5000}, {6, 60, 6000}, {7, 70, 7000},
{8, 80, 8000}, {9, 90, 9000}, {10, 100, 10000}}
A not so neat alternative is:
In[4]:= ReadList["comma.dat", Table[Word,{3}], WordSeparators->","]
Out[4]= {{"1", "10", "1000"}, {"2", "20", "2000"},
{"3", "30", "3000"}, {"4", "40", "4000"},
{"5", "50", "5000"}, {"6", "60", "6000"},
{"7", "70", "7000"}, {"8", "80", "8000"},
{"9", "90", "9000"}, {"10", "100", "10000"}}
In[5]:= Map[ToExpression,%,{2}]
Out[5]= {{1, 10, 1000}, {2, 20, 2000}, {3, 30, 3000},
{4, 40, 4000}, {5, 50, 5000}, {6, 60, 6000},
{7, 70, 7000}, {8, 80, 8000}, {9, 90, 9000}, {10, 100, 10000}}
Perhaps the URL for this question and answer should be updated?
Cheers,
Paul
_________________________________________________________________
Paul Abbott
Department of Physics Phone: +61-9-380-2734
The University of Western Australia Fax: +61-9-380-1014
Nedlands WA 6907 paul at physics.uwa.edu.au
AUSTRALIA http://www.pd.uwa.edu.au/Paul
_________________________________________________________________
==== [MESSAGE SEPARATOR] ====