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.