Re: comma delimited output file -- modify existing code?
- To: mathgroup at smc.vnet.net
- Subject: [mg31882] Re: [mg31869] comma delimited output file -- modify existing code?
- From: Rob Pratt <rpratt at email.unc.edu>
- Date: Sun, 9 Dec 2001 06:07:05 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
> A year ago or so, some kind soul gave me the very valuable > method of writing a tab delimited array to a text file. Due > to incompetence on my part, I don't have his name. Anyway, > here is his code that works nicely: > > writeArray[filename_, arrayname_] := > Module[{makeStringList, outfile}, outfile = OpenWrite[filename]; > makeDepth3[lst_] := Module[{x}, x = lst; While[Depth[x] < 3, x = {x}]; > While[Depth[x] > 3, x = Flatten[x, 1]]; x]; > makeStringList[lst_] := > Flatten[{Drop[ > Flatten[Transpose[{Map[ToString, lst], > Table["\t", {Length[lst]}]}]], -1], {"\n"}}]; > Scan[WriteString[outfile, Sequence @@ makeStringList[#]] &, > makeDepth3[arrayname], {1}]; Close[outfile]] > > writeArray["filename.txt", wList]; > > My data in wList goes nicely into a tab delimited file. > > Now, I'd like to make it a comma delimited file but (again > due to an amazing incompetence) I can't figure out how to > modify it for commas. The "/t" shure looks like the culprit > but when I change it to "/c" I don't get commas but '/c' as > delimiters. So it is the delimiter spec but what is the > comma spec?? I haven't checked if this works, but what about "," instead of "/c"? Alternatively, you might just use Export[filename, expression, "CSV"]. Rob Pratt Department of Operations Research The University of North Carolina at Chapel Hill rpratt at email.unc.edu http://www.unc.edu/~rpratt/