On Mon, 5 Jun 2017, Sven Schreiber wrote:
Am 05.06.2017 um 14:36 schrieb Allin Cottrell:
> On Sat, 3 Jun 2017, Filipe Rodrigues da Costa wrote:
>> I need to compute the cross-sectional mean and standard deviation and I
>> want NAs to be ignored, as they are in a series. Is there a simple way
>> of doing this?
>
> There isn't a "built-in" way, but one could write a hansl function to
do
> it. Here's a simple example.
...
or what about using the selecting function selifc():
set skip_missings off
matrix m = {L}
matrix result = {}
loop i=1..rows(m)
result |= meanr( selifc(m, ok(m[i])) )
# and analogous with sdc( selifc(...)' )'
endloop
series mymeans = result
(untested)
Something quite similar works OK (and is more concise than what I
posted). But to get the desired result the first argument to selifc()
must be a row vector, not the whole "m" matrix:
<hansl>
function series my_list_mean2 (list L)
set skip_missing off
matrix m = {L}
matrix result = {}
loop i=1..rows(m)
matrix mi = m[i,]
result |= meanr(selifc(mi, ok(mi)))
# and analogous with sdc(selifc(...)')'
endloop
series mymeans = result
return mymeans
end function
</hansl>
Allin Cottrell