Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Importing data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113430] Re: Importing data
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 28 Oct 2010 04:27:34 -0400 (EDT)

On 10/27/10 at 5:18 AM, dhi67540 at bigpond.net.au (David Higgins)
wrote:

>Relatively new user here.  I have a text file containing 540,000
>lines of data in 30 columns, fixed width.  Not all columns are
>populated for all data lines.

>When I import, Mathematica creates a list and populates the list
>elements from 1 to the number of data elements it finds in each
>line, ignoring the empty columns so for data lines with only, say 20
>columns populated, it has populated data elements 1 to 20 instead of
>skipping the missing ones.  Is there a way to import data that
>allows me to define a template for the data elements so that the
>right data ends up in the right elements in the list?

Yes. I would do this by using ReadList to read in the data as a
string, split the string up according to the fixed width and use
ToExpression to convert non-empty fields to numeric values as
needed. If the data is simply empty fields and numbers, this
method might actually take less time than using Import.



  • Prev by Date: Re: Manually nested Tables faster than builtin nesting?
  • Next by Date: Mathematica's text + graphics GUI
  • Previous by thread: Importing data
  • Next by thread: Re: Importing data