On Mon, 4 Aug 2014, Logan Kelly wrote:
> Quick suggestion. Could a function called varnames() be added that is
> like varname() except it returns an array with the names of variables
> in a list. For example:
varname() already does that, except that since it predates string arrays what
it returns when given a list argument is a single string containing the names of
the member series separated by commas.
Sure, and what I am sugesting can be easily achieved by
strings ret = strsplit(strsub(varname(in),","," "))
where "in" is a list. But that seemed a bit clunky. Having the names in an array
would be helpful when you need the variable names as strings in a loop. For example, this
came up when I was using the chowlin() function to interpolate monthly data.
<hansl>
matrix mdatamat = chowlin(qdatamat,3,xdatamat)
strings qdatanames = varnames(qdatalist) #note this finction is standing in for
strsplit(strsub(varname(qdatalist),","," "))
loop foreach i qdatalist --quiet
sprintf seriesname "%s_m", qdatanames[i]
series @seriesname = mdatamat[,i]
endloop
</hansl>
Just a thought. (Also, I may just be making the task much harder than it need be.)
Cheers,
Logan