I have a large list of values which – for presentation in my LaTeX document – I need to format. For instance: I have calculated growth rates which I now would like to have formatted in the form of:
In[2260]:= Map[{First[First[#]],NumberForm[N[Last[#]],3,2}]}&,
CompleteQuarterlyStatDataBySubjects[[1]][[1]]]
Out[2260]= {{Australia,{}},{Austria,-1.21},{Belgium,-1.46},{Canada,-1.30},
{Czech Republic,-1.67},{Denmark,-1.87},{Estonia,-3.97},{Finland,-2.53},
{France,-1.00},{Germany,-1.74},{Greece,-1.16},{Hungary,-1.45},
{Iceland,-1.83}, {Ireland,-1.67},{Israel,{}},{Italy,-1.42},{Japan,-0.69},
{Korea, {}},{Luxembourg,-1.67},{Netherlands,-0.98},{New Zealand,-0.50},
{Norway,-0.64},{Poland,{}},{Portugal,-0.40},{Slovak Republic,{}},
{Slovenia,-3.31},{Spain,-0.71},{Sweden,{}},{Switzerland,-0.82},
{Turkey,-3.39},{United Kingdom,-1.45},{United States,-1.28}}
(the original dataset CompleteQuarterlyStatDataBySubjects[[1]][[1]]
is at the bottom of this post)
Besides growth rates I have calculated AbsoluteTime
-Values which I would like to format as follows:
In[2271]:= Map[
{
First[First[#]],
Table[
DateString[#[[2;;-1]][[i]],{"Quarter"," ","Year"}],
{i,Length[#[[2;;-1]]]}
]
}&,
CompleteQuarterlyStatDataBySubjects[[1]][[5]]
]
Out[2271]= {{Australia,{DateString[{},{Quarter, ,Year}]}},{Austria,{1 2008}},
{Belgium,{2 2008}},{Canada,{3 2008}},{Czech Republic,{3 2008}},
{Denmark,{2 2008}},{Estonia,{2 2008}},{Finland,{2 2008}},
{France,{1 2008}},{Germany,{1 2008}},{Greece,{3 2008}},
{Hungary,{1 2008}},{Iceland,{3 2008}},{Ireland,{4 2007}},
{Israel,{DateString[{},{Quarter, ,Year}]}},{Italy,{1 2008}},
{Japan,{1 2008,3 2010}},{Korea,{DateString[{},{Quarter, ,Year}]}},
{Luxembourg,{1 2008}},{Netherlands,{1 2008}},{New Zealand,{4 2007}},
{Norway,{2 2008}},{Poland,{DateString[{},{Quarter, ,Year}]}},
{Portugal,{4 2007,3 2010}},{Slovak Republic,{DateString[{},
{Quarter, ,Year}]}},{Slovenia,{3 2008}},{Spain,{1 2008}},
{Sweden,{DateString[{},{Quarter, ,Year}]}},{Switzerland,{2 2008}},
{Turkey,{1 2008}},{United Kingdom,{1 2008}},{United States,{2 2008}}}
To automate the process of getting the values into the right format, I thought to use the following approach:
In[2261]:= Formats[list_,x_]:=
If[x==1,
NumberForm[N[list],{3,2}]
If[x==5,
Table[DateString[list[[i]],{"Quarter"," ","Year"}],{i,Length[list]}]
]
]
And then to type for example:
Map[
{
First[First[#]],
Formats[Last[#],1]
}&,
CompleteQuarterlyStatDataBySubjects[[1]][[1]]
]
Unfortunately that did not work! Does anyone has an idea how I can program a procedure to get my data automatically formatted?
The original data is:
In[2259]:= CompleteQuarterlyStatDataBySubjects[[1]][[1]]
Out[2259]= {{{Australia,AUS,other countries,GDP,quarterly data},{}},{{Austria,AUT,western European
countries,GDP,quarterly data},-1.2056},{{Belgium,BEL,western European
countries,GDP,quarterly data},-(7288960271654/4985881289361)},{{Canada,CAN,G7,GDP,quarterly data},-1.30053},{{Czech Republic,CZE,eastern European
countries,GDP,quarterly data},-(2134917223477606900/1282008490172233089)},{{Denmark,DNK,nothern European
countries,GDP,quarterly data},-(48057014595630800665/25700334274612164804)},{{Estonia,EST,eastern European
countries,GDP,quarterly data},-3.9659},{{Finland,FIN,nothern European
countries,GDP,quarterly data},-(33199059446612625/13128459048331036)},{{France,FRA,G7,GDP,quarterly data},-(5130109517723890585/5148852459134416857)},{{Germany,DEU,G7,GDP,quarterly data},-1.73904},{{Greece,GRC,southern European
countries,GDP,quarterly data},-1.164},{{Hungary,HUN,eastern European
countries,GDP,quarterly data},-(2225003087375671762980417961289391847/1539154631936274189423508152574973424)},{{Iceland,ISL,nothern European
countries,GDP,quarterly data},-1.83398},{{Ireland,IRL,nothern European
countries,GDP,quarterly data},-1.67021},{{Israel,ISR,other countries,GDP,quarterly data},{}},{{Italy,ITA,G7,GDP,quarterly data},-1.42009},{{Japan,JPN,G7,GDP,quarterly data},-(673269612770377724744620/262544695052599501095431),-(32760683814040103590/47201698472568566589)},{{Korea,KOR,other countries,GDP,quarterly data},{}},{{Luxembourg,LUX,western European
countries,GDP,quarterly data},-1.67073},{{Netherlands,NLD,western European
countries,GDP,quarterly data},-0.97505},{{New Zealand,NZL,other countries,GDP,quarterly data},-(152151059187768664247/302333262014074402254)},{{Norway,NOR,nothern European
countries,GDP,quarterly data},-(33596749386427335752225/52657796909983176600514)},{{Poland,POL,eastern European
countries,GDP,quarterly data},{}},{{Portugal,PRT,southern European
countries,GDP,quarterly data},-0.785963,-0.398132},{{Slovak Republic,SVK,eastern European
countries,GDP,quarterly data},{}},{{Slovenia,SVN,eastern European
countries,GDP,quarterly data},-3.31102},{{Spain,ESP,southern European
countries,GDP,quarterly data},-(2414923435622638997136189344226575/3392598745831412249336953513454508)},{{Sweden,SWE,nothern European
countries,GDP,quarterly data},{}},{{Switzerland,CHE,western European
countries,GDP,quarterly data},-0.820439},{{Turkey,TUR,other countries,GDP,quarterly data},-3.38638},{{United Kingdom,GBR,G7,GDP,quarterly data},-(2047013335956949212233044315/1411710881613564347284381614)},{{United States,USA,G7,GDP,quarterly data},-(2091354065961931475/1636350606517650408)}}
and for the AbsoluteTime-Values:
In[2265]:= CompleteQuarterlyStatDataBySubjects[[1]][[5]]
Out[2265]= {{{Australia,AUS,other countries,GDP,quarterly data},{}},{{Austria,AUT,western European
countries,GDP,quarterly data},3408134400},{{Belgium,BEL,western European
countries,GDP,quarterly data},3415996800},{{Canada,CAN,G7,GDP,quarterly data},3423859200},{{Czech Republic,CZE,eastern European
countries,GDP,quarterly data},3423859200},{{Denmark,DNK,nothern European
countries,GDP,quarterly data},3415996800},{{Estonia,EST,eastern European
countries,GDP,quarterly data},3415996800},{{Finland,FIN,nothern European
countries,GDP,quarterly data},3415996800},{{France,FRA,G7,GDP,quarterly data},3408134400},{{Germany,DEU,G7,GDP,quarterly data},3408134400},{{Greece,GRC,southern European
countries,GDP,quarterly data},3423859200},{{Hungary,HUN,eastern European
countries,GDP,quarterly data},3408134400},{{Iceland,ISL,nothern European
countries,GDP,quarterly data},3423859200},{{Ireland,IRL,nothern European
countries,GDP,quarterly data},3400185600},{{Israel,ISR,other countries,GDP,quarterly data},{}},{{Italy,ITA,G7,GDP,quarterly data},3408134400},{{Japan,JPN,G7,GDP,quarterly data},3408134400,3486931200},{{Korea,KOR,other countries,GDP,quarterly data},{}},{{Luxembourg,LUX,western European
countries,GDP,quarterly data},3408134400},{{Netherlands,NLD,western European
countries,GDP,quarterly data},3408134400},{{New Zealand,NZL,other countries,GDP,quarterly data},3400185600},{{Norway,NOR,nothern European
countries,GDP,quarterly data},3415996800},{{Poland,POL,eastern European
countries,GDP,quarterly data},{}},{{Portugal,PRT,southern European
countries,GDP,quarterly data},3400185600,3486931200},{{Slovak Republic,SVK,eastern European
countries,GDP,quarterly data},{}},{{Slovenia,SVN,eastern European
countries,GDP,quarterly data},3423859200},{{Spain,ESP,southern European
countries,GDP,quarterly data},3408134400},{{Sweden,SWE,nothern European
countries,GDP,quarterly data},{}},{{Switzerland,CHE,western European
countries,GDP,quarterly data},3415996800},{{Turkey,TUR,other countries,GDP,quarterly data},3408134400},{{United Kingdom,GBR,G7,GDP,quarterly data},3408134400},{{United States,USA,G7,GDP,quarterly data},3415996800}}