Reputation: 10607
I'm very new to Mathematica. I want to use it as a data source for gnuplot (I know Mathematica can plot too), it uses a file format with data in columns and a space between each column on each row. Like this:
x y
1 123
2 234
4 456
etc.
I've come as far as to create this expression:
{CountryData["G8"], CountryData[#, "GDP"] & /@ CountryData["G8"]} // Transpose // Grid
This creates a table just like I want it. Now, how can I export this to a file not as matrix but as a table like it appears in Mathematica?
Upvotes: 3
Views: 10074
Reputation: 16232
Your CountryData
usage can be streamlined a bit using the map operator /@
:
{#, CountryData[#, "GDP"]} & /@ CountryData["G8"],
Combining this with Export
you get this:
Export[
"C:\\Users\\Sjoerd\\Desktop\\tabel.txt",
{#, CountryData[#, "GDP"]} & /@ CountryData["G8"],
"Table",
"FieldSeparators" -> " "
]
Replace the above file path with something appropriate for your situation.
Upvotes: 5
Reputation: 4420
Mathematica supports a wide range of Export formats. Something like Export["mytable.csv",nameofexpression]
should do the trick, Export["file.dat",nameofexpression,"Table"]
for space /tab delimited.
This tutorial should help.
Upvotes: 4