我想要一個類似於 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>