Import timeseries via loop (pot. generic)

荒凉一梦 提交于 2019-12-24 05:51:28

问题


Solved, now working example!

I have a set of time series that is populated in a folder structure as follows:

TimeSeriesData\Config_000000\seed_001\Aggregate_Quantity.txt
…
TimeSeriesData\Config_000058\seed_010\Aggregate_Quantity.txt

And in each file there is a first line containing a character, followed by lines containing the data. E.g.

share
-21.75
-20.75
…

Now, I would like to import all those files (at best, without specifying ex post the number of configs and seeds, at worst with supplying it) into single time series of the like: “AggQuant_config_seed” where config relates to the config ID and seed to the seed id.

I tried the following (using the non-preferred way), but “parsing” the “path” does not work / I do not know how to do it.

string base = "TimeSeriesData/Config_"
string middle = "/seed_"
string endd = "/Aggregate_Quantity.txt"
string path = ""
loop for (i=0;i<=58;i+=1)
    loop for (j=1;j<=10;j+=1)
        path = ""
        sprintf path "%s%06d%s%03d%s",base,i,middle,j,endd
        append @path #will be named share
        rename share Agg_Q_$i_$j #rename
    endloop
endloop 

To sum up the problem, the following does not work:

string path="somwhere/a_file.txt" #string holding path
#wrong: append $path #use append on string
append @path #works!

And if possible, a way to search recursively through a set of folders, using the folder information together with file-information for the variable name, would be nice. Is that possible within gretl?

I realize that in many cases I would like to refer to a specific “help” section like those for functions and commands, but for operators instead (like “$”, which is obviously wrong here).

来源:https://stackoverflow.com/questions/40931619/import-timeseries-via-loop-pot-generic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!