In his answer to this question, Leonid helped me find a way to programmatically generate contexts for holding sets of symbols with the same names. Perhaps a simpler way is to use DownValues
so:
dataRaw["Paris"] = Import["Paris.csv"];
data["Paris"] = Differences[dataRaw["Paris"]];
dataMax["Paris"] = Max[dataRaw["Paris"]];
dataRaw["Madrid"] = Import["Madrid.csv"];
data["Madrid"] = Differences[dataRaw["Madrid"]];
dataMax["Madrid"] = Max[dataRaw["Madrid"]];
lets me make a plot using
ListLinePlot[data /@ {"Paris", "Madrid"}]
and can be implemented with a simple function
importCity[cityName_String] := (
dataRaw[cityName] = Import[cityName ~~ ".csv"];
data[cityName] = Differences[dataRaw[cityName]];
dataMax[cityName] = Max[dataRaw[cityName]];
)
Other than cluttering everything with a lot of [cityName]
, are there hidden perils to using DownValues
in this way? Is there some disadvantage to storing every dataRaw
as DownValues
of the same symbol instead of individually in multiple contexts?
"paris"
andToLowerCase
rather than simply"Paris"
? $\endgroup$ – Mr.Wizard♦ Mar 15 '12 at 18:22