Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Reading tables with labels

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5614] Re: Reading tables with labels
  • From: Count Dracula <lk3a at watt.seas.virginia.edu>
  • Date: Fri, 27 Dec 1996 23:43:42 -0500
  • Organization: University of Virginia
  • Sender: owner-wri-mathgroup at wolfram.com

William R. Pearson wrote:
> 
> I would like to read a table that looks like this:
> 
> name        len lamr   lamv   kr     kv
> FEPE         54 0.2316 0.1544 0.4582 0.2030
> H3NJ1W       60 0.2136 0.1826 0.1589 0.1244
> NTSRIA       64 0.2087 0.1614 0.1730 0.1117
> N2KF1U       74 0.2115 0.1560 0.1416 0.0826
> LWBOA        75 0.1774 0.1910 0.0335 0.0352
> LWPMA        81 0.1797 0.1809 0.0375 0.0378
> 
> Into two lists, one with the name of the column and a second with
> the actual values of the columns.  I can read the data with ReadList[],
> but of course it chokes on the initial labels.

readtable[infile_String, ncol_Integer] :=
   Module[{inf = OpenRead[infile]},
     {Rest[ReadList[inf, Word, ncol]],
      Rest[Transpose[ReadList[inf, Join[{Word}, Table[Number, {ncol - 1}]]]]]}
         ]

Output for the sample file from `readtable["inputfile", 6]` is

Out[4]= {{len, lamr, lamv, kr, kv}, {{54, 60, 64, 74, 75, 81}, 

   {0.2316, 0.2136, 0.2087, 0.2115, 0.1774, 0.1797}, 
 
   {0.1544, 0.1826, 0.1614, 0.156, 0.191, 0.1809}, 
  
   {0.4582, 0.1589, 0.173, 0.1416, 0.0335, 0.0375}, 
 
   {0.203, 0.1244, 0.1117, 0.0826, 0.0352, 0.0378}}}

-- 
____________________________________________________________
Levent Kitis                          University of Virginia
Department of Mechanical, Aerospace, and Nuclear Engineering
____________________________________________________________


  • Prev by Date: Re: Re: Re: How to get rid of the outer {}?
  • Next by Date: HELP: Legendre transform
  • Previous by thread: Re: Reading tables with labels
  • Next by thread: How to get rid of the outer {}?