我想要一个类似于 Col Moving Average() 的内置函数,用于计算 a 列的移动(滚动)分位数。 您可以将其称为 Col Moving Quantile() 和/或 Col Moving Median()。
我编写了一个用户函数(附后),它对于小型表来说足够有效,但它使用了一种非常低效的方法。 我绝对确定有更有效的方法来实现此功能,并且不涉及在每个滚动步骤中进行强力重新计算。 这些方法超出了我的编码能力。
</CODE></P><PRE><CODE class=" language-jsl">Add Custom Functions(
New Custom Function(
"x",
"Col Moving Quantile",
Function( {col, p, before, after, dt = Current Data Table()},
{coldata = Column( dt, col ) << Get As Matrix, from = Max( Row() - before, 1 ), to, to = Min( Row() + after, N Rows( dt ) )},
Quantile( p, coldata[Index( from, to )] )
)
)
// === Documentation ===
<<FORMULA category=""> )" ) //
<<PARAMETER></PARAMETER></FORMULA>