On Sat, 15 Oct 2011, artur bala wrote:

> Could it be possible for a function to pass a series as boolean? If the
> series is provided it can act like a "- - by" flag.

You can pass a pointer-to-series as an optional argument (with 
a default of "null").

If I've correctly understood what you want, here's a simple 
example. We have a function that computes the sum of its 
(first) series argument, x. But if a second argument, y, is 
given it instead computes two sums, returned in a vector, 
namely the sum of (x at observations where y==0) and
sum of (x at observations where y!=0).

<hansl>
function matrix foo (series x, series *y[null])
   matrix ret
   if isnull(y)
     print "no y"
     ret = {sum(x)}
   else
     print "got y"
     ret = {sum(x*(y==0)), sum(x*(y!=0))}
   endif
   return ret
end function

nulldata 20
series x = normal()
series y = uniform() > 0.5
matrix m = foo(x, &y)
print m
matrix m = foo(x)
print m
</hansl>

Allin Cottrell

Reply via email to