MathGroup Archive 1996

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

Search the Archive

Re: Re: help! to input data...

  • To: mathgroup at
  • Subject: [mg4282] Re: [mg4228] Re: help! to input data...
  • From: John Fultz <jfultz>
  • Date: Sat, 29 Jun 1996 03:53:57 -0400
  • Sender: owner-wri-mathgroup at

> In article <4pit53$jk5 at>, tcdoe+ at 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, 20, 6, 7, 8}

There was no comma at the end of the first line, so Mathematica took this as
implicit multiplication.  You'll get the wrong data in and never be the wiser
unless you verified the data.

A correct solution for the original data file...that is, something of the


could be:

Map[First, ReadList["d:\\tmp\\foo", {Number, Character}]]

A more general solution is:

ToExpression[ReadList["d:\\tmp\\foo", Word, WordSeparators->{","}]]

An even more general solution which would allow you to read data in rows
and thus preserve the 2-dimensionality is:

ToExpression[ReadList["d:\\tmp\\foo", Word, WordSeparators->{","},

However, if memory serves me correctly, the first solution is somewhat
faster if it suits your purpose.


John Fultz
jfultz at
Applications Group
Wolfram Research, Inc.

  • Prev by Date: sound display
  • Next by Date: repetitive complex operation
  • Previous by thread: Re: help! to input data...
  • Next by thread: Running Mathematica 2.1 under Windows95?