Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

TSV files as a list of list of lists?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101150] TSV files as a list of list of lists?
  • From: Dan-Erik Lindberg <mathforums.org at dan-erik.com>
  • Date: Thu, 25 Jun 2009 07:13:50 -0400 (EDT)

I am loading a few GPS data files as TSV (tab separated). What I would like to do is make the loading of files a bit more dynamic, so I make a list of the file contents. But since the file contents is a list in itself, I get in trouble when I want to manipulate the data. It just takes too long.

First, here is how I do it for one file only:

GPS1 = Import["F:\\Documents\\Jobb\\SLU\\xyuvw\\GPS.txt", "TSV"]
(* Remove column-headers *)
GPS1 = Drop[GPS1, 1] 
(* Make sure row 1 of column 2 or 3 doesn't contain spaces so \
they can be interpreted as numbers (I use swedish RT90 \
grid which gives coordinates in meters). *)
If[Head[GPS1[[1, 2]]] == String, 
  GPS1[[All, 2]] = 
   ToExpression[StringReplace[GPS1[[All, 2]], " " -> ""]]];
If[Head[GPS1[[1, 3]]] == String, 
  GPS1[[All, 3]] = 
   ToExpression[StringReplace[GPS1[[All, 3]], " " -> ""]]];
(* Sort the GPS data (first column is time) *)
Sort[GPS1] 


Now, what I would like to do; make an array of file contents (actually a list):


GPS[1] = Import["F:\\Documents\\Jobb\\SLU\\xyuvw\\GPS.txt","TSV"];
Do[GPS[1] = ReplacePart[GPS[1], {i,2} -> \
ToExpression[StringReplace[GPS1[[All, 2]], " " -> ""]]], {i, 1, \
Length[GPS[1]]}];
Sort[GPS[1]] 

This second part takes a very long time to do, because ReplacePart[] has to work through every line one at a time rather than using [All, x] as I do in the first example. 

Is there any way of doing this faster?


  • Prev by Date: Re: Possible bug in Mathematica 7 using ColorFunction
  • Next by Date: Re: *slowing down* a Mathematica process (Dynamic/Refresh question)
  • Previous by thread: Re: Wolfram | Alpha: Acres per square mile? (oddities)
  • Next by thread: stirring chocolate pudding backwards: identifying coordinates