And this too :-)
Leon
Am 19.02.2013 um 19:13 schrieb Allin Cottrell <cottrell(a)wfu.edu>:
On Mon, 18 Feb 2013, Pindar wrote:
> in this little function 'zeromiss' is applied to a list and a new list is
> returned.
> Ok so far, but it is possible to overwrite the already existing series or to
> apply the original labels to the new series?
>
> <hansl>
> function list zeroNA(list variables)
> list X = null
> loop foreach i variables -q
> series $i = zeromiss(variables.$i)
> X+= $i
> endloop
> return X
> end function
> <hansl>
Hmm, this exposes a bug: if the caller picks up the list
return value, you end up with two series under each of the
names in the input list. That's now fixed in CVS.
On your second point, there's no automatic way of applying the
original series labels to the new series, though you can
resort to writing the labels out to file then reading them
back, as in
<hansl>
function list zeroNA (list L)
list Lmiss = null
loop foreach i L -q
series $i = zeromiss(L.$i)
Lmiss += $i
endloop
return Lmiss
end function
nulldata 20
series x = uniform()
series y = uniform()
x = x > .2 ? x : 0
y = y > .2 ? y : 0
setinfo x -d "this is series x"
setinfo y -d "this is series y"
labels --to-file="labels.txt"
list L = x y
print L -o
L = zeroNA(L)
labels --from-file="labels.txt"
print L -o
labels
</hansl>
Allin Cottrell
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users