# How to output Mathematica Lists as a Table to a file?

Given the following List:

  lis =  { {-2.8336, -1.1088, -0.1232, 1.23493}, {-2.8336, -1.1088, 0.1232,
1.08433}, {-2.8336, -0.8624, -0.616,
1.04417}, {-2.8336, -0.8624, -0.3696,
1.10441}, {-2.8336, -0.8624, -0.1232, 1.17469}, {-2.8336, -0.8624,
0.1232, 1.09437}, {-2.8336, -0.8624, 0.3696,
1.43574}, {-2.8336, -0.8624, 0.616,
1.07429}, {-2.8336, -0.616, -0.8624,
1.26506}, {-2.8336, -0.616, -0.616, 1.43574} }


One can convert it to a table as follows: lis//TableForm

But that just works for displaying it in Mathematica. How can one easily save that list to a text file so that it appears as a table?

-
To me, a table is more than a string of text, for example, of ASCII characters. It implies some sort of structure or formatting. For what applications would you like the output to appear as a table? –  David Carraher Mar 3 '13 at 4:59
@DavidCarraher, I just want to read in the data as a text file for a visualization program. Also to use it for other procedural programming languages that read text files in that format. –  RunnyKine Mar 3 '13 at 5:03
This was pretty obvious from looking up Export in the documentation. –  Verbeia Mar 3 '13 at 5:13

I don't know if this will work for you, but you might try something simple such as

data = {
{-2.8336, -1.1088, -0.1232, 1.23493},
{-2.8336, -1.1088, 0.1232, 1.08433},
{-2.8336, -0.8624, -0.616, 1.04417},
{-2.8336, -0.8624, -0.3696, 1.10441},
{-2.8336, -0.8624, -0.1232, 1.17469},
{-2.8336, -0.8624, 0.1232, 1.09437},
{-2.8336, -0.8624, 0.3696, 1.43574},
{-2.8336, -0.8624, 0.616, 1.07429},
{-2.8336, -0.616, -0.8624, 1.26506},
{-2.8336, -0.616, -0.616, 1.43574}
};

Export[FileNameJoin[{\$HomeDirectory, "Desktop", "test.csv"}], data]


This produces a file with the following content:

-2.8336,-1.1088,-0.1232,1.23493
-2.8336,-1.1088,0.1232,1.08433
-2.8336,-0.8624,-0.616,1.04417
-2.8336,-0.8624,-0.3696,1.10441
-2.8336,-0.8624,-0.1232,1.17469
-2.8336,-0.8624,0.1232,1.09437
-2.8336,-0.8624,0.3696,1.43574
-2.8336,-0.8624,0.616,1.07429
-2.8336,-0.616,-0.8624,1.26506
-2.8336,-0.616,-0.616,1.43574

-

A quick look at the documentation for Export reveals that Mathematica supports a range of Export formats and that there is a guide on how to import and export data in different formats.

In that guide it states:

Export["file", list, "Table"] writes out data separated by spaces, with numbers given in C or Fortran-like form, as in 2.3E5 and so on.

This documentation page might also be useful.

-
And add this question for formatting problems. –  Sjoerd C. de Vries Mar 3 '13 at 12:45