Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,50 @@
>type median
function median (x, v: none, p)
## Default for v : none
## Default for p : 0.5
m=rows(x);
if m>1 then
y=zeros(m,1);
loop 1 to m;
y[#]=median(x[#],v,p);
end;
return y;
else
if v<>none then
{xs,i}=sort(x); vsh=v[i];
n=cols(xs);
ns=sum(vsh);
i=1+p*(ns-1); i0=floor(i);
vs=cumsum(vsh);
loop 1 to n
if vs[#]>i0 then
return xs[#];
elseif vs[#]+1>i0 then
k=#+1;
repeat;
if vsh[k]>0 or k>n then break; endif;
k=k+1;
end;
return (1-(i-i0))*xs[#]+(i-i0)*xs[k]+0;
endif;
end;
return xs[n];
else
xs=sort(x);
n=cols(x);
i=1+p*(n-1); i0=floor(i);
if i0==n then return xs[n]; endif;
return (i-i0)*xs[i+1]+(1-(i-i0))*xs[i];
endif;
endif;
endfunction
>median(1:10)
5.5
>median(1:9)
5
>median(1:10,p=0.2)
2.8
>0.2*10+0.8*1
2.8