Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Re: [mg4228] Re: help! to input data...
Replies: 0

 Jason Welter Posts: 4 Registered: 12/7/04
Re: [mg4228] Re: help! to input data...
Posted: Jul 11, 1996 12:44 AM

In article <4qqn4c\$49m@dragonfly.wolfram.com>, jfultz@wolfram.com says...
>
>> In article <4pit53\$jk5@dragonfly.wolfram.com>, tcdoe+@pitt.edu says...
>> >
>> >well, silly me.
>> >I thought i was pretty good at the basics of mathematica, but today i
>> >tried to input some numerical data that was comma delimited. i.e.
>> >
>> >456,-45,21,0,5
>> >43,25,3,66,65
>> >...
>> >...
>> >...
>> >
>> >it is a large data file (10Mb+) with 5 numbers per line. i can't
>> >convert the commas to tabs easily.

>>
>> You don't need to convert the commas to tabs.
>>
>> Solution #1: Open the file and put a "{" before the first number
>> and a "}" after the last. This creats one big list and can be
>> read in using something like data = <<"C:\\temp\\data.txt";

>
>BAD!! Don't do this! You will get erroneous data and Mathematica will
>never tell you there were any errors. Here's what happens. Create the
>sample data file:
>
>{1,2,3,4
>5,6,7,8}

This is close but not the way real comma delimited files look. I took his
word for it and assumed it was really comma delimited. If the data did look like:

1,2,3,4
5,6,7,8

then it would be comma and return delimited. If that was the case, a global
search and replace of the return character with either a "," + return or
"},{" + return is easy enough.

In either case I find it easier to do the search and replace than to remember
"Map[First, ReadList["d:\\tmp\\foo", {Number, Character}]]"! Can it get any
more obscure?

BUT...

John, do you know of a way to read this into MMA:

# TestName[ACT245P ] [ PMC1] [ PMC2] [ PMC3] [ PMC4] [ PMC5]
---------------------- ---------- ---------- ---------- ---------- ----------
1 [CONTI_M1 ] & 0.00000 & 1.00000 & 1.00000 & 1.00000 & 2.00000

# TestName[ACT245P ] [ PMC1] [ PMC2] [ PMC3] [ PMC4] [ PMC5]
---------------------- ---------- ---------- ---------- ---------- ----------
2 [CA_GOI_GOE_NM ] -19.5000 -19.3000 -19.6000 -20.0000 -19.7000
3 [CA_GOI_GOE_PM ] 18.0000 17.8000 18.0000 18.4000 18.2000
4 [CH_1.00_NM_TR ] 121.853 115.612 188.382 168.093 273.507
5 [CH_1.00_NM_TH ] 125.392 162.555 164.442 244.348 251.892
6 [CH_1.00_PM_TR ] 3.44601 3.30223 3.10842 3.45061 4.58194
7 [CH_1.00_PM_TH ] 2.25403 2.03261 2.07853 2.33058 3.10277

# TestName[ACT245P ] [ PMC1] [ PMC2] [ PMC3] [ PMC4] [ PMC5]
---------------------- ---------- ---------- ---------- ---------- ----------
1 [CONTI_M1 ] & 0.00000 & 1.00000 & 1.00000 & 1.00000 & 2.00000

# TestName[ACT245P ] [ PMC1] [ PMC2] [ PMC3] [ PMC4] [ PMC5]
---------------------- ---------- ---------- ---------- ---------- ----------
2 [CA_GOI_GOE_NM ] -19.5000 -19.3000 -19.6000 -20.0000 -19.7000
3 [CA_GOI_GOE_PM ] 18.0000 17.8000 18.0000 18.4000 18.2000
4 [CH_1.00_NM_TR ] 121.853 115.612 188.382 168.093 273.507
5 [CH_1.00_NM_TH ] 125.392 162.555 164.442 244.348 251.892
6 [CH_1.00_PM_TR ] 3.44601 3.30223 3.10842 3.45061 4.58194
7 [CH_1.00_PM_TH ] 2.25403 2.03261 2.07853 2.33058 3.10277

etc.

I have about a dozen files each hundreds of K large and am having to load it into
Excel, parse & sort & prep for mathematica. I need the numbers to be recognized as
numbers by MMA, not characters. Ideally the data would look like:

{{1,{1,0.00000,1.00000,1.00000,1.00000,2.00000},
{2,-19.500,-19.300,-19.600,-20.000,-19.700},
{3,18.0000,17.8000,18.0000,18.4000,18.2000},
{4,121.853,115.612,188.382,168.093,273.507},
{5,125.392,162.555,164.442,244.348,251.892},
{6,3.44601,3.30223,3.10842,3.45061,4.58194},
{7,2.25403,2.03261,2.07853,2.33058,3.10277}},
{2,{1,0.00000,1.00000,1.00000,1.00000,2.00000},
{2,-19.500,-19.300,-19.600,-20.000,-19.700},
{3,18.0000,17.8000,18.0000,18.4000,18.2000},
{4,121.853,115.612,188.382,168.093,273.507},
{5,125.392,162.555,164.442,244.348,251.892},
{6,3.44601,3.30223,3.10842,3.45061,4.58194},
{7,2.25403,2.03261,2.07853,2.33058,3.10277}}}

Jason Welter