MathGroup Archive 2002

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

Search the Archive

Re: How to read mixed-type data from external files?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37688] Re: How to read mixed-type data from external files?
  • From: Bill Rowe <listuser at earthlink.net>
  • Date: Fri, 8 Nov 2002 02:16:19 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 11/7/02 at 6:41 AM, wfhsiao at libra.seed.net.tw (Wen-Feng Hsiao)
wrote:

>Suppose the type of the second column is String, the others are
>numbers.
>
>In[1]:=!! data.csv 
> 1,WEIGHT,97.5,1123,371,50,25,0.1,2.2046223
> 2,STATURE,797.5,1944,1385,50,25,0.1,0.3937008
> 3,VERTICAL GRIP RCH,957.5,2332,1674,50,30,0.1,0.3937008
> 4,FRONTAL GRIP REACH,337.5,831,580,20,10,0.1,0.3937008
> 5,LATERAL GRIP REACH,462.5,1108,773,25,15,0.1,0.3937008
> 6,STEP HEIGHT,207.5,942,572,25,15,0.1,0.3937008
> 7,SUPINE STATURE,897.5,1925,1441,50,25,0.1,0.3937008
> 8,STANDING CG F FEET,507.5,1075,810,20,15,0.1,0.3937008

>
>I tried the following code, but in vain. Could someone help me this
>out?
>
>snum = OpenRead["data.csv"] data = ReadList[ snum, {Number, String,
>Number, Number, Number, Number, Number, Number, Number}] Close[snum]

The easiest way to do this would be to use Import instead of ReadList as in

Import["data.csv"]

You can also use ReadList but you will need to use the RecordSeparators option combined with the RecordLists option. Import takes care of this issue automatically.

BTW, you don't need an OpenRead statement for ReadList. ReadList automatically opens and closes the file.


  • Prev by Date: Re: Numerical Algorithm for Blasius Equation
  • Next by Date: Misbehaving Sum[..,{n,0,Infinity}]
  • Previous by thread: RE: How to read mixed-type data from external files?
  • Next by thread: Re: How to read mixed-type data from external files?